在Azure Webjobs SDK中设置nextVisibleTime [英] Set nextVisibleTime in Azure Webjobs SDK

查看:103
本文介绍了在Azure Webjobs SDK中设置nextVisibleTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure Webjobs处理队列中的消息.

I'm using Azure Webjobs to process messages from a queue.

我看到Webjobs SDK在10分钟后再次处理任何失败的消息,并且如果失败5次,则会将其移至中毒队列(

I saw that the Webjobs SDK processes any failed message again after 10 minutes, and it if fails 5 times it moves it to the poison queue (1).

我还可以在插入时间(

Also I can see the nextVisibleTime of the message in the queue, that is 10 minutes after the insertionTime (2).

我想对消息使用AzureSDK错误处理,但是我不能等待10分钟才能再次处理消息.

I want to use the AzureSDK error handling of the messages but I cannot wait 10 minutes for the message to be processed again.

有什么办法可以将nextVisibleTime设置为几秒钟?

Is there any way I can set this nextVisibleTime to a few seconds?

创建一个Azure App Service中的.NET WebJob

如果该方法在完成之前失败,则不会删除队列消息; 10分钟的租约期满后,该邮件将被释放以再次被拾起并进行处理.

If the method fails before completing, the queue message is not deleted; after a 10-minute lease expires, the message is released to be picked up again and processed.

注意:StackOverflow中也有类似的问题,但没有答案:

Note: There are similar questions here in StackOverflow but with no answer:

  • QueueTrigger Attribute Visibility Timeout
  • Azure WebJob QueueTrigger Retry Policy

推荐答案

在最新的v1.1.0版本中,您现在可以通过注册自己的自定义 QueueProcessor 实例来控制可见性超时. JobHostConfiguration.Queues.QueueProcessorFactory .这使您可以全局或按队列/功能控制高级消息处理行为.

In the latest v1.1.0 release, you can now control the visibility timeout by registering your own custom QueueProcessor instances via JobHostConfiguration.Queues.QueueProcessorFactory. This allows you to control advanced message processing behavior globally or per queue/function.

例如,要设置失败消息的可见性,您可以按如下所示覆盖 ReleaseMessageAsync :

For example, to set the visibility for failed messages, you can override ReleaseMessageAsync as follows:

protected override async Task ReleaseMessageAsync(CloudQueueMessage message, FunctionResult result, TimeSpan visibilityTimeout, CancellationToken cancellationToken)
{
    // demonstrates how visibility timeout for failed messages can be customized
    // the logic here could implement exponential backoff, etc.
    visibilityTimeout = TimeSpan.FromSeconds(message.DequeueCount);

    await base.ReleaseMessageAsync(message, result, visibilityTimeout, cancellationToken);
}

更多详细信息,请参见此处的发行说明

More details can be found in the release notes here.

这篇关于在Azure Webjobs SDK中设置nextVisibleTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆