Azure PaaS Blog articles

Azure PaaS Blog articles

https://techcommunity.microsoft.com/t5/azure-paas-blog/bg-p/AzurePaaSBlog

Azure PaaS Blog articles

Azure Storage | How to migrate Azure Queue Data from One Account to Another

Published

Azure Storage | How to migrate Azure Queue Data from One Account to Another

Storage queues are like service bus queue, the messages are not designed to store permanent like blobs/files, once the receiver processes the messages, they would be deleted. As queues use a publisher subscriber model, and the data is transient it may be easiest to recreate the queue. Please follow the below steps to migrate Azure Queue Data from one Storage account to another storage account:

  • List all queues from the source storage account.
  • create queues with the same names in the Target Storage account.
  • Read every message from the source and write them to the destination.

Guidelines:

  1. Your client must have network access to both the source and destination storage accounts. To learn how to configure the network settings for each storage account, see Configure Azure Storage firewalls and virtual networks | Microsoft Learn
  2. Append a SAS token to REST API calls as needed.
  3. We assume process described in this blog requires user to develop an application of their own choice by leveraging azure storage client libraries as mentioned in Technical documentation | Microsoft Learn
  4. Ensure your application can access and both source and target storage accounts and configured with appropriate roles.
  5. The examples in this article assume that you've authenticated your identity by using your storage account with SAS key for making REST API calls.

 

  1. List all queues from the source storage account.

Request:

The List Queues lists all the queues in each storage account. This request may be constructed as follows. HTTPS is recommended. Replace storage account with the name of your storage account:

 

rpadi450_11-1677851021911.png

 

Response:

 

rpadi450_12-1677851021917.png

 

  1. Create queues with the same names in the Target storage account.

The Create Queue operation creates a queue in a storage account.

Request:

The Create Queue request may be constructed as follows. HTTPS is recommended. Replace storageaccountname with the name of your storage account:

rpadi450_13-1677851021921.png

 

Response:

The response includes an HTTP status code and a set of response headers. A successful operation returns status code 201 (Created).

rpadi450_14-1677851021925.png

      Refer to below official documentation for the details specific to response headers

  1. Read every message from the source and write them to the destination
  • Read message from Source storage account.

 

The Get Messages operation retrieves one or more messages from the front of the queue.

            Request:

The Get Messages request may be constructed as follows. HTTPS is recommended. Replace myaccount with the name of your storage account, and myqueue with the name of your queue:

            

rpadi450_15-1677851021929.png

       Response:

The response includes an HTTP status code and a set of response headers. A successful operation returns status code 200 (OK).

 

rpadi450_16-1677851021940.png

  • Write message to Target storage account.

The Put Message operation adds a new message to the back of the message queue. A visibility timeout can also be specified to make the message invisible until the visibility timeout expires. A message must be in a format that can be included in an XML request with UTF-8 encoding. The encoded message can be up to 64 KiB in size for versions 2011-08-18 and newer, or 8 KiB in size for previous versions.

Request:

The Put Message request may be constructed as follows. HTTPS is recommended. Replace storageaccount with the name of your storage account, and myqueue with the name of your queue:

rpadi450_17-1677851021944.png

 

            Request Body:

The body of the request contains the message data in the following XML format. Note that the message content must be in a format that may be encoded with UTF-8.

<QueueMessage>      <MessageText>message-content</MessageText>  </QueueMessage> 

 

Response:

The response includes an HTTP status code and a set of response headers. A successful operation returns status code 201 (Created).

 

rpadi450_18-1677851021953.png

Once the POST operation is successful, you can check if the queue/message is copied properly by visiting source and target storage account.   

Source Storage account:

rpadi450_19-1677851021960.png

 

 

Target Storage account:

 

rpadi450_20-1677851021963.png

 

  1. Upon the message is successfully written into the destination queue or PUT operation is successful. We need to delete the queue from source queue.

       The Delete Queue operation permanently deletes the specified queue.

Request:

You can construct the Delete Queue request as follows. HTTPS is recommended. Replace myaccount with the name of your storage account.

 

 

rpadi450_21-1677851021968.png

 

 Response:

A successful operation returns status code 204 (No Content). For information about status codes, see Status and error codes.

 

 

Continue to website...

More from Azure PaaS Blog articles