How to clear Azure ServiceBus Queue using Azure Portal | Message time to live in service bus

{tocify} $title={Table of Contents}

Scenario


I was testing a logic app which is queue based . While testing found some changes to be done in the test data - did that and started the testing again.

But as the message volume of testing was high the earlier messages were still in queue and thus had to wait for old messages to get processed and the new ones to be picked.



Unbounded Time to live in Service Bus Queue


To  expedite the process started to Recieve and Delete individual messages via Service Bus explorer in Portal. But it was too laborious and time consuming.

Also there were 7K+ messages in the queue. 

So the next thought was, why don't we have option to clear the queue using Portal? 

Message time to Live(TTL)


One of the property of messages in Service Bus Queue is Message time to Live(TTL).

The expiration for any individual message can be controlled by setting the time-to-live i.e. it indicates a time span for which a message will live inside a queue. 

If the message is not processed by that time, it will either be removed or dead-lettered.

Based On the Service Bus tier, the maximum ttl differs, minimum is 5 seconds
  • For the basic tier, the default (also maximum) expiration time is 14 days.
  • For Standard and Premium tier, the maximum expiration time is 10675199 days.

How to use Message time to Live(TTL) to clear service bus queue


We are using premium tier and and as can be seen TTL was set to maximumMaximum message time to live


So if message is not processed, it will remain there for 10675198 days. 

Now, my need was to clear those messages as I wanted new set of messages to be tested.

The trick used here is to make the time to live to it's minimum - 5 seconds. 

minimum value of message time to live



This forced the messages to be removed in 5 seconds - not all at once as it depends on Maximum Delivery Count property( It can also be changed).

In few minutes all messages were removed.



I again reset the TTL to maximum and pumped in new set of messages for testing.


Note: This is not recommended for Production.



If you know better way to clear the service bus message queue , you can share it in comments !!!





Do share if you find this helpful .......
 
                          Knowledge Sharing is Caring !!!!!!



4 Comments

If you have any suggestions or questions or want to share something then please drop a comment

  1. Any suggestions for clearing Dead Letter Queue messages from Production env?

    ReplyDelete
  2. Did not work for me. Messages are still there.

    ReplyDelete
  3. Did not work for me either... messages are still there.

    ReplyDelete
  4. Thank you!! Try waiting a bit extra. Worked for me, removed 10k messages

    ReplyDelete
Previous Post Next Post