Azure Function and storage queue, what to do if function fails

萝らか妹 提交于 2019-12-17 13:54:09

问题


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.

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.

My questions:

  1. Am I right, that when you trigger a function on a new queue item, the function takes the message and deletes it from the queue, even if the function fails?
  2. If 1 is correct, how do you make sure that the message is retried and posted to a dead queue for later processing?

回答1:


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.

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. :)



来源:https://stackoverflow.com/questions/40006372/azure-function-and-storage-queue-what-to-do-if-function-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!