触发Azure队列存储而不删除消息 [英] Azure Queue Storage triggered without removing message

查看:57
本文介绍了触发Azure队列存储而不删除消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在决定删除消息之前,如何在功能应用程序"中保留消息?

How can I keep a message in the "function App" until I decide to remove it?

当我使用c#构建控制台应用程序时,可以决定何时删除读取的消息:

When I build a console app in c#, I can decide when I remove the message that I read with:

queue.DeleteMessage(msg);

我能够通过以下过程自动读取队列:

I'm able to read the queue automatically with this procedure: functions-create-storage-queue-triggered-function.

问题是,就像Azure所说的那样:

The problem is, like Azure said:

  1. 回到Storage Explorer中,单击刷新"并确认消息已被处理并且不再在队列中.

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

In this context, I can't remove the message by myself when the function is done.

我试图抛出新的Exception("failed"); 来模拟一个失败的函数,但是无论如何该消息都被删除了.

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

我希望将此消息保留在队列中,直到我决定删除它为止(在函数末尾).

I'm looking to keep this message in queue until I decide to remove it (At the end of the function).

推荐答案

我试图抛出新的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()的原因.您只会收到消息,而不是队列客户端.

The message isn't removed, it goes invisible for whatever the visibility-timeout is in seconds. You are running your code in the context of the WebJobs SDK, that's why you can't call .DeleteMessage() on your own. You are only being handed the message, not the queue client.

如果您的Function成功完成,则该消息将由Functions运行时(WebJobs SDK)删除.

If your Function completes successfully, then the message will be removed by the Functions runtime (WebJobs SDK).

参考:
https://stackoverflow.com/a/40011705/4148708
https://github.com/Azure/azure-webjobs-sdk/issues/1040

出队计数也可以咬人.如果消息的 dequeueCount 属性达到5,WebJobs SDK会将消息移至中毒队列( QueueName-poison ).

Dequeue count can also bite. WebJobs SDK will move the message to the poison queue (QueueName-poison) if the message dequeueCount property reaches 5.

更多信息,请参见:
查看全文

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