18

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?
Oak3
  • 943
  • 7
  • 20

1 Answers1

33

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

mathewc
  • 13,312
  • 2
  • 45
  • 53
  • Thanks very much. I was confused because running the console I read that the message was made invisible for 60 seconds. Can I change that invisible time when I use an Azure Function? – Oak3 Oct 13 '16 at 08:08
  • That can't be customized currently, though we have an issue tracking making that customizable [here](https://github.com/Azure/azure-webjobs-sdk/issues/844) in our repo. If you need this ability, feel free to chime in on that issue. However, for most scenarios, the 10 minute value works just fine. If the above has answered your question, please mark as answered, thanks :) – mathewc Oct 13 '16 at 14:49
  • It would be nice if it immediately became visible again upon failure. Is that on the roadmap? – Larry Maccherone Nov 15 '16 at 16:12
  • We have an open issue in our repo [here](https://github.com/Azure/azure-webjobs-sdk/issues/844) tracking that. Feel free to chime in on that with your scenario. – mathewc Nov 15 '16 at 16:25
  • @mathewc, does all of this great documentation relevant to Azure Functions as well? – johni Dec 04 '17 at 08:21
  • 1
    By "no error has occurred" are you specifically referring to exceptions? In other words, does the function have to throw an exception to avoid the dequeue? – jrichview Jul 31 '18 at 18:30
  • 1
    Unfortunately, it appears that "How to handle poison messages" is nowhere to be found in the provided link, nor in the wiki that contains it. – Mike-E Oct 13 '20 at 13:24