How to move message in Azure Service Bus Queue

sbq-logo

At times, you want to move the message between more than one azure service bus queue. Back in 2015, there were tools like service bus explorer and doesn’t support moving the message in a bulk. I wrote a small C# code to move the messages in a bulk between the azure service bus queues. It is useful for scenarios like

    • Backup the unprocessed messages between service bus queues during a production deployment
    • Backup the unprocessed messages between service bus queues during a system outage
    • Move the messages to a different service bus queue to manage the application load etc

If it happens to you and finding a solution for it, then you land up in the correct place!

Before I discuss how to do it, let me give a quick introduction of the azure service bus queue. Azure Service bus queue offers simple first-in, first-out guaranteed message delivery. It provides high availability with support for enterprise-level messaging. In general, the message comes in and goes out from the service bus queue and known as a brokered message. It stores inside the service bus queue in a serialized format. The client library sets the serialization format of the message during a send operation. It could be JSON, binary, XML, etc based on the implementation. Azure also offers azure storage queue as a messaging service for a distributed environments. There are differences between them and outlined here.

The C# code snippet below moves the message between the source and destination queue. It retains the serialization format of the brokered message while moving. You can tweak the C# code to set the destination to a different queue or a deadletter queue of an azure service bus.

Please add the service bus queue package from the NuGet repository before running the code. It is worth mentioning that you cannot use the brokered message if it is already accessed. In such cases, you can create a new message by cloning the existing brokered message.

Conclusion

Let me wrap it up here. The key takeaway of this blog post is to provide a small code snippet for moving the messages in a bulk. The code snippet is a sample one and you can extend it further according to the needs. I hope you like the article. Please leave a comment with your feedback, share it with your friends and colleagues.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.