问题描述
我正在使用Azure Webjobs处理队列中的消息.
I'm using Azure Webjobs to process messages from a queue.
我看到Webjobs SDK在10分钟后再次处理任何失败的消息,并且如果失败5次,则会将其移至中毒队列( 1 ).
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).
我还可以在插入时间( 2 ).
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
public static void WriteLog([QueueTrigger("logqueue")] string logMessage,
DateTimeOffset expirationTime,
DateTimeOffset insertionTime,
DateTimeOffset nextVisibleTime,
注意: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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!