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}");
}
Create a Queue
Use the QueueClient to create a new queue.
import com.azure.storage.queue.QueueClient;
import com.azure.storage.queue.QueueServiceClient;
import com.azure.storage.queue.QueueServiceClientBuilder;
public class ManageQueues {
public static void main(String[] args) {
String connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
String queueName = "my-new-queue-java";
// Create a QueueClient object
QueueClient queueClient = new QueueClient(connectionString, queueName);
// Create the queue
queueClient.create();
System.out.println("Queue '" + queueName + "' created successfully.");
}
}
Delete a Queue
Use the QueueClient to delete a queue.
import com.azure.storage.queue.QueueClient;
import com.azure.storage.queue.QueueServiceClient;
import com.azure.storage.queue.QueueServiceClientBuilder;
public class ManageQueues {
public static void main(String[] args) {
String connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
String queueName = "my-queue-to-delete-java";
// Create a QueueClient object
QueueClient queueClient = new QueueClient(connectionString, queueName);
// Delete the queue
queueClient.delete();
System.out.println("Queue '" + queueName + "' deleted successfully.");
}
}
List Queues
Use the QueueServiceClient to list all queues in your storage account.
import com.azure.storage.queue.QueueClient;
import com.azure.storage.queue.QueueServiceClient;
import com.azure.storage.queue.QueueServiceClientBuilder;
import com.azure.storage.queue.models.QueueItem;
public class ManageQueues {
public static void main(String[] args) {
String connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
// Create a QueueServiceClient object
QueueServiceClient queueServiceClient = new QueueServiceClientBuilder()
.connectionString(connectionString)
.buildClient();
System.out.println("Listing queues:");
for (QueueItem queueItem : queueServiceClient.listQueues()) {
System.out.println("- " + queueItem.getName());
}
}
}
Create a Queue
Use the QueueClient to create a new queue.
from azure.storage.queue import QueueClient
connection_string = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
queue_name = "my-new-queue-python"
# Create a QueueClient object
queue_client = QueueClient.from_connection_string(connection_string, queue_name)
# Create the queue
queue_client.create_queue()
print(f"Queue '{queue_name}' created successfully.")
Delete a Queue
Use the QueueClient to delete a queue.
from azure.storage.queue import QueueClient
connection_string = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
queue_name = "my-queue-to-delete-python"
# Create a QueueClient object
queue_client = QueueClient.from_connection_string(connection_string, queue_name)
# Delete the queue
queue_client.delete_queue()
print(f"Queue '{queue_name}' deleted successfully.")
List Queues
Use the QueueServiceClient to list all queues in your storage account.
from azure.storage.queue import QueueServiceClient
connection_string = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
# Create a QueueServiceClient object
queue_service_client = QueueServiceClient.from_connection_string(connection_string)
print("Listing queues:")
for queue_item in queue_service_client.list_queues():
print(f"- {queue_item.name}")
Create a Queue
Use the QueueClient to create a new queue.
const { QueueClient } = require("@azure/storage-queue");
const connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
const queueName = "my-new-queue-js";
// Create a QueueClient object
const queueClient = new QueueClient(connectionString, queueName);
async function createQueue() {
await queueClient.createQueue();
console.log(`Queue '${queueName}' created successfully.`);
}
createQueue().catch(err => console.error(err));
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.
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.