Azure Function Queue 触发器:如何为出队消息设置时间延迟

Azure Function Queue trigger: how to set time delay for dequeue message

我有一个 Azure Function,它侦听 azure queue,例如,有些错误。它再次将消息重新添加到队列中。但在 5 次后消息将被移动到毒队列。

我想将消息重新添加到延迟队列中。例如,重试 1 小时。因为我的 Azure Functions 使用外部资源,目前可能不可用。我根本不想在 10 秒内重试 5 次,我想在 1 小时后重试。当然,我自己写了它的实现,但可能这个功能已经存在了。

@4c74356b41 指出了正确的方法。 host.json 队列设置就是您要找的。

visibilityTimeout is The time interval between retries when processing of a message fails maxDequeueCount is The number of times to try processing a message before moving it to the poison queue.

{
    "version": "2.0",
    "extensions": {
        "queues": {
            "visibilityTimeout" : "01:00:00",
            "maxDequeueCount": 2
        }
    }
}

如果你的函数是v1,同样

{
    "queues": {
      "visibilityTimeout" : "01:00:00",
      "maxDequeueCount": 2
    }
}

更新

由于问题主要是根据具体情况改变visibilityTimeout,所以相应地设置CloudQueue.AddMessageAsync的延迟是唯一的办法。实际上 visibilityTimeout 做的是完全相同的事情,但是在功能应用程序级别(所有队列),所以在这种情况下我们不需要坚持它。