Azure 队列存储在未删除消息的情况下触发

Azure Queue Storage triggered without removing message

如何在 "function App" 中保留一条消息,直到我决定将其删除?

当我在 C# 中构建控制台应用程序时,我可以决定何时删除我阅读的消息:

queue.DeleteMessage(msg);

我可以使用以下过程自动读取队列:functions-create-storage-queue-triggered-function

问题是,如 Azure 所说:

  1. Back in Storage Explorer, click Refresh and verify that the message has been processed and is no longer in the queue.

在这种情况下,我无法在功能完成后自行删除消息。

我试图 Throw new Exception("failed"); 模拟一个失败的功能,但消息还是被删除了。

我希望将此消息保留在队列中,直到我决定将其删除(在函数结束时)。

I tried to Throw new Exception("failed"); to simulate a failed function but the message is removed anyway.

该消息未被删除,它在 visibility-timeout 秒后消失。您是 WebJobs SDK 上下文中的 运行 您的代码,这就是为什么您不能自己调用​​ .DeleteMessage() 的原因。您只收到消息,而不是队列客户端。

如果您的函数成功完成,则该消息将被函数运行时 (WebJobs SDK) 删除。

参考:

https://github.com/Azure/azure-webjobs-sdk/issues/1040

编辑: 出队计数也可以咬人。如果消息 dequeueCount 属性 达到 5.

,WebJobs SDK 会将消息移至病毒队列 (QueueName-poison)

查看更多:
https://github.com/Microsoft/azure-docs/blob/master/articles/app-service-web/websites-dotnet-webjobs-sdk-storage-queues-how-to.md#automatic-poison-message-handling