What's the proper way to abandon an Azure SB Message so that it becomes visible again in the future in a way I can control? What's the proper way to abandon an Azure SB Message so that it becomes visible again in the future in a way I can control? azure azure

What's the proper way to abandon an Azure SB Message so that it becomes visible again in the future in a way I can control?


If you want to put a message away for a while and you have a place to write down the SequenceNumber (which might be in Session state in a sessionful queue), you can Defer() it. Deferred messages can be retrieved using a special Receive overload giving the SequenceNumber; that's also the only way to get at them again other than them expiring, so careful. This feature was built for workflows and state machines so that they can deal with out of order message arrival.


In bullet #2 above: Can't you just set the TTL timespan on the message when calling Receive(TimeSpan) instead of the default Receive()? Then, you can simply abandon the message (without calling Abandon()), and the message should reappear in the queue when the TTL expires. While this doesn't give you fine-grain control to say "Reappear after x seconds," it does give you predictability for when the message does reappear.

Note: With Storage-based queues, you can update the invisibility timeout, so that would give you fine-grain control for message re-appearance.


Feels a bit hacky, but the solution I came up with is

try {   ...}catch (Exception ex){   await Task.Delay(30000);   throw;}

This way it will wait for 30 seconds before allowing it to abandon. It will eventually dead letter after the configured amount of times.

I am using Azure Webjobs for receiving.Although I am using Task.Delay instead of Thread.Sleep it doesn't seem to be freeing up the thread to process another item from the queue while it awaits (by default, Webjobs processes 16 in parallel).