Azure Queue Storage is a service for storing large numbers of messages that can be accessed by authenticated clients from anywhere in the world. It is a message queueing service that enables you to decouple your applications and scale them independently.
Here’s a step-by-step guide on how to create an Azure Queue Storage account and use it with CLI commands:
Step 1: Create an Azure Queue Storage account
- Log in to the Azure portal (https://portal.azure.com/).
- In the left pane, click on “Create a resource”.
- In the search bar, type “Queue Storage” and select the “Queue Storage” option.
- Click on the “Create” button.
- In the “Create Queue Storage Account” window, fill in the required information such as the subscription, resource group, storage account name, location, and performance.
- Click on the “Review + create” button to validate the settings and create the storage account.
- Once the validation is successful, click on the “Create” button.
Step 2: Get the connection string for your Queue Storage account
- After the storage account is created, navigate to the “Overview” tab in the left-hand menu and click on the “Access keys” option.
- Copy the “Connection string” value under “key1” or “key2” section.
Step 3: Use Azure CLI to create and manage Queue Storage
- Install Azure CLI on your local machine (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).
- Open the command prompt or terminal on your local machine.
- Log in to your Azure account using the following command: az login
- Create a new Queue Storage using the following command:
az storage queue create --account-name <storage_account_name> --account-key <storage_account_key> --name <queue_name>
<storage_account_name>
: the name of your storage account.<storage_account_key>
: the access key for your storage account.<queue_name>
: the name of the queue you want to create.
- Add a message to the queue using the following command:
az storage message put --account-name <storage_account_name> --account-key <storage_account_key> --queue-name <queue_name> --content <message_content>
<storage_account_name>
: the name of your storage account.<storage_account_key>
: the access key for your storage account.<queue_name>
: the name of the queue where you want to add the message.<message_content>
: the content of the message you want to add to the queue.
- Get the message count and list of messages in the queue using the following command:
az storage message peek --account-name <storage_account_name> --account-key <storage_account_key> --queue-name <queue_name>
<storage_account_name>
: the name of your storage account.<storage_account_key>
: the access key for your storage account.<queue_name>
: the name of the queue you want to view the messages for.
- Retrieve and delete the next message in the queue using the following commands:
az storage message get --account-name <storage_account_name> --account-key <storage_account_key> --queue-name <queue_name>
<storage_account_name>
: the name of your storage account.<storage_account_key>
: the access key for your storage account.<queue_name>
: the name of the queue you want to retrieve the message from.
To delete the message that was retrieved in the previous step, use the following command:
az storage message delete --account-name <storage_account_name> --account-key <storage_account_key> --queue-name <queue_name> --id <message_id> --popreceipt <pop_receipt>
<storage_account_name>
: the name of your storage account.<storage_account_key>
: the access key for your storage account.<queue_name>
: the name of the queue where the message is stored.<message_id>
: the ID of the message you want to delete.<pop_receipt>
: the receipt that was returned when the message was retrieved.
- Delete a Queue Storage using the following command:
az storage queue delete --account-name <storage_account_name> --account-key <storage_account_key> --name <queue_name>
<storage_account_name>
: the name of your storage account.<storage_account_key>
: the access key for your storage account.<queue_name>
: the name of the queue you want to delete.
That’s it! You’ve now learned how to create an Azure Queue Storage account and manage it using Azure CLI commands. You can use these commands to create, add messages to, view, retrieve, and delete queues, and messages in your Queue Storage account.