我正在使用 Azure Webjobs 处理来自队列的消息。
我看到 Webjobs SDK 在 10 分钟后再次处理任何失败的消息,如果失败 5 次,它会将其移动到毒药队列 (1)。
我还可以看到队列中消息的 nextVisibleTime,即插入时间后 10 分钟( 2 )。
我想使用 AzureSDK 错误处理消息,但我不能等待 10 分钟再次处理消息。
有什么办法可以将 nextVisibleTime 设置为几秒钟?
Create a .NET WebJob in Azure App Service
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.
How to use Azure queue storage with the WebJobs SDK
public static void WriteLog([QueueTrigger("logqueue")] string logMessage,
DateTimeOffset expirationTime,
DateTimeOffset insertionTime,
DateTimeOffset nextVisibleTime,
注意:StackOverflow 中也有类似的问题,但没有答案:
最佳答案
在最新的 v1.1.0 版本中,您现在可以通过注册自己的自定义 来控制可见性超时。队列处理器 实例通过 JobHostConfiguration.Queues.QueueProcessorFactory .这允许您全局或按队列/函数控制高级消息处理行为。
例如,要设置失败消息的可见性,您可以覆盖 ReleaseMessageAsync 如下:
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);
}
更多详情请见 release notes here .
关于azure-webjobs - 在 Azure Webjobs SDK 中设置 nextVisibleTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31244721/