Azure 函数和存储队列,函数失败怎么办 [英] Azure Function and storage queue, what to do if function fails

查看:27
本文介绍了Azure 函数和存储队列,函数失败怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个向 Azure 存储队列发布消息的场景.出于测试目的,我开发了一个控制台应用程序,我可以在其中获取消息并使用尝试计数更新它,当逻辑完成后,我会删除该消息.

I'm working out a scenario where a post a message to an Azure Storage Queue. For testing purposes I've developed a console app, where I get the message and I'm able to update it with a try count, and when the logic is done, I delete the message.

现在我正在尝试将我的代码移植到 Azure 函数.似乎非常不同的一件事是,当调用 Azure Function 时,消息从队列中删除.

Now I'm trying to port my code to an Azure Function. One thing that seems to be very different is, when the Azure Function is called, the message is deleted from the queue.

我发现很难找到关于这个特定主题的任何文档,而且我觉得我在将这两者结合的概念方面遗漏了一些东西.

I find it hard to find any documentation on this specific subject and I feel I'm missing something with regard to the concept of combining these two.

我的问题:

  1. 我说得对吗,当您在新队列项上触发函数时,即使函数失败,该函数也会获取消息并将其从队列中删除?
  2. 如果 1 是正确的,您如何确保消息被重试并发布到死队列以供以后处理?

推荐答案

运行时仅在您的函数成功处理队列消息(即没有发生错误)时删除队列消息.当消息出列并传递给您的函数时,它会在一段时间(10 分钟)内不可见.当您的函数运行时,这种不可见性会保持不变.如果您的函数失败,消息不会被删除 - 它以不可见的状态保留在队列中.可见性超时后,该消息将再次在队列中可见以进行重新处理.

The runtime only deletes the queue message when your Function successfully processes it (i.e. no error has occurred). When the message is dequeued and passed to your function, it becomes invisible for a period of time (10 minutes). While your function is running this invisibility is maintained. If your function fails, the message is not deleted - it remains in the queue in an invisible state. After the visibilty timeout expires, the message will become visible in the queue again for reprocessing.

可以找到核心 WebJobs SDK 队列处理如何工作的详细信息 此处.在该页面上,请参阅解决您的问题的如何处理有害消息"部分.基本上,您将免费获得所有正确的行为 - 重试处理、有害消息处理等 :)

The details of how core WebJobs SDK queue processing works can be found here. On that page, see the section "How to handle poison messages" which addresses your question. Basically you'll get all the right behaviors for free - retry handling, poison message handling, etc. :)

这篇关于Azure 函数和存储队列,函数失败怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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