Search code examples
azureazureservicebusazure-webjobsazure-servicebus-queues

Azure Web Jobs, Azure Service Bus Queue Trigger prevent message from getting deleted


I am looking into setting up a web job trigger to read message from service bus queue. What would be the best practice to implement a retry logic in case of any errors handling the downstream systems.

Would we be able to throw an exception so that the message will not be deleted from the queue and will be retried after certain time period?

Appreciate your feedback.


Solution

  • You don't need to define retry logic explicitly. When the message is de-queued from service bus , it gets invisible from queue for certain time period (lock time default 30secs , you can configure it). You try to process the message , if it gets successful you simply call BrokeredMessage.CompleteAsync which means i am done and mark this message as completed. If you have some problem in down stream you can abandon the message by calling BrokeredMessage.AbandonAsync . This will unlock the message and the message appears back in the queue. The message will be picked up by the worker again and process it. Until you get successful or reach the max retry limit after which the message is send to dead letter queue.