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

1

19

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?
Darcydarda answered 12/10, 2016 at 19:0 Comment(0)
C
35

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

Crutchfield answered 13/10, 2016 at 3:14 Comment(9)
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?Darcydarda
That can't be customized currently, though we have an issue tracking making that customizable here 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 :)Crutchfield
It would be nice if it immediately became visible again upon failure. Is that on the roadmap?Canzona
We have an open issue in our repo here tracking that. Feel free to chime in on that with your scenario.Crutchfield
@mathewc, does all of this great documentation relevant to Azure Functions as well?Judas
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?Riebling
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.Deconsecrate
Now the link is a 404 also.Spaulding
This does not seem to be the case, thrown an exception in the run method will remove the item from the queue still as of today.Firelock

© 2022 - 2024 — McMap. All rights reserved.