QueueTrigger属性可见性超时 [英] QueueTrigger Attribute Visibility Timeout

查看:614
本文介绍了QueueTrigger属性可见性超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我是用Azure.Storage.Queue从队列中得到一个消息

If I were to get a message from queue using Azure.Storage.Queue

queue.GetMessage(TimeSpan.FromMinutes(20));

试图用Azure.WebJobs(SDK 0.4.0-β)时,我可以设置可见性超时,但是属性一个webjob自动绑定到一个队列

I can set the visibility timeout, however when trying to use Azure.WebJobs (SDK 0.4.0-beta) attributes to auto bind a webjob to a queue

public static void ProcessQueueMessage([QueueTrigger("myqueue")] string message){
       //do something with queue item
}

有没有一种方法来设置该属性的可见性超时?似乎没有要在JobHostConfiguration()队列的选项。如果没有办法覆盖,难道是标准的30秒钟,然后?

Is there a way to set the visibility timeout on the attribute? There does not seem to be an option in JobHostConfiguration().Queues. If there is no way to override, is it the standard 30 seconds then?

推荐答案

在最新的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);
}

更多的细节可以在发行说明这里

这篇关于QueueTrigger属性可见性超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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