How to Manage Azure Storage Queues

This article explains how to manage Azure Storage queues. You can manage queues using the Azure portal, Azure CLI, Azure PowerShell, or client libraries.

Create a Queue

Use the QueueClient to create a new queue.


using Azure.Storage.Queues;

string connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
string queueName = "my-new-queue";

// Create a QueueClient object
QueueClient queueClient = new QueueClient(connectionString, queueName);

// Create the queue
queueClient.Create();

Console.WriteLine($"Queue '{queueName}' created successfully.");
                    

Delete a Queue

Use the QueueClient to delete a queue.


using Azure.Storage.Queues;

string connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
string queueName = "my-queue-to-delete";

// Create a QueueClient object
QueueClient queueClient = new QueueClient(connectionString, queueName);

// Delete the queue
queueClient.Delete();

Console.WriteLine($"Queue '{queueName}' deleted successfully.");
                    

List Queues

Use the QueueServiceClient to list all queues in your storage account.


using Azure.Storage.Queues;

string connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";

// Create a QueueServiceClient object
QueueServiceClient queueServiceClient = new QueueServiceClient(connectionString);

Console.WriteLine("Listing queues:");
await foreach (var queueItem in queueServiceClient.GetQueuesAsync())
{
    Console.WriteLine($"- {queueItem.Name}");
}
                    

Queue Operations

You can perform various operations on Azure Storage queues, including creating, deleting, listing, and getting queue metadata. The following sections provide details and code examples for common management tasks.

Creating a Queue

When you create a queue, you specify a unique name for it within your storage account. Queue names must be between 3 and 63 characters long and adhere to certain naming conventions.

Note: Queue names are case-insensitive.

Deleting a Queue

Deleting a queue removes it and all of its messages from your storage account. This operation is irreversible.

Important: Ensure you have backed up any critical messages before deleting a queue.

Listing Queues

You can retrieve a list of all queues within your storage account. This is useful for inventory management and automation.

Getting Queue Metadata

You can retrieve metadata for a specific queue, such as its approximate message count and last modified time.

API Reference

Create Queue: QueueClient.Create(), az storage queue create, New-AzStorageQueue

Delete Queue: QueueClient.Delete(), az storage queue delete, Remove-AzStorageQueue

List Queues: QueueServiceClient.GetQueuesAsync(), az storage queue list, Get-AzStorageQueue

Get Queue Metadata: QueueClient.GetProperties()

Tip: For managing queues at scale, consider using Azure Resource Manager (ARM) templates or Terraform for infrastructure as code.

This article covers the fundamental management operations for Azure Storage queues. For detailed information on specific client libraries or advanced scenarios, please refer to the corresponding documentation.