Move messages in Service Bus Queue

sbq-logo
If you want to know how to move the messages between two azure service bus queue for situations like production deployment or during a system outage or move the messages to a different service bus queue to manage the huge load etc, then you are landed up on a correct place. Before I show you how to do it, let me give a quick introduction of azure service bus queue.
Service bus queue offers simple first in, first out guaranteed message delivery, highly available with support for enterprise level messaging. Microsoft also offers Azure REST queue as a messaging service for distributed environment and the difference are outlined here. The message that comes in and goes out from service bus queue is called brokered message and it stores inside the service bus queue in a serialized format. The format could be JSON, binary, xml etc. which can be set during the send operation to the service bus queue. This tool retains the serialized message and move the same message to a different queue or a deadletter queue. Following code snippet is a simple console application which does the message movement between source and destination queue.

Before running the code, make sure to add the package from nuget repository. If you are accessing the message before sending it, you have to create a clone of the message because brokered message cannot be used in case the body of the message is already accessed (code is commented). Deadletter queue can be used as a destination queue and can be referred as {queue_name}/$deadletterqueue