16
votes

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

1 Answers

31
votes

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