我让Azure函数在QueueTrigger上运行,但如果DequeueCount(最大重试次数)超过设置的限制,我希望在不向有毒队列发送消息的情况下完成该函数(但继续向有毒队列发送其他失败的消息)
我当前的函数如下所示:
public async Task ProcessThis([QueueTrigger("message-queue")] Message message, string id, string popReceipt, int dequeueCount, ILogger logger)
{
try
{
...
//process queue here
...
}
catch (Exception e)
{
if (dequeueCount == this._config.DequeueCount) //Currently it's set to 10
{
return; //If I return here, would the message still go into poison queue?
}
throw e;
}
}
我想知道,如果消息由于超过最大重试次数而失败,这是不是防止消息进入有毒队列的正确方法。
发布于 2020-07-16 05:14:15
如果函数没有抛出异常,Azure函数运行时会将其视为成功处理的消息,并将其从Q中删除。
如果抛出任何类型的异常,则运行时将其视为失败,并递增出队计数。如果新的计数超过maxDequeueCount
,它将被移动到毒害Q. See doc。
因此,如果你不想要任何东西去毒害Q,只需向你的ProcessThis()
添加一个catch-all代码块并抑制异常。
发布于 2020-07-15 06:25:26
不确定最大队列计数是多少,但本文有一个方便的变通方法。只是
requeue the message。你也可以使用subscribe to the poison queue,然后重新排队
https://stackoverflow.com/questions/62902546
复制相似问题