Create a Queue

Azure Queues is a service that provides reliable, scalable message queuing for various cloud applications. This document outlines the steps to create a new queue using different methods.

Important: Queue names must be 3 to 63 characters long and can contain lowercase letters, numbers, and hyphens. Queue names must start and end with a letter or number.

Prerequisites

Create a Queue using Azure SDKs

Azure SDK for .NET

To create a queue using the .NET SDK, you'll need the Azure.Storage.Queues package.

// Install the package:
// dotnet add package Azure.Storage.Queues

using Azure.Storage.Queues;

public class QueueCreator
{
    public static async Task CreateQueueAsync(string connectionString, string queueName)
    {
        // Create a QueueClient object
        var queueClient = new QueueClient(connectionString, queueName);

        // Create the queue
        await queueClient.CreateAsync();

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

Azure SDK for Python

To create a queue using the Python SDK, install the azure-storage-queue library.

# Install the package:
# pip install azure-storage-queue

from azure.storage.queue import QueueClient

def create_queue(connection_string: str, queue_name: str):
    # 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.")

# Example usage:
# connection_str = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
# queue_n = "my-new-queue"
# create_queue(connection_str, queue_n)

Create a Queue using Azure CLI

You can use the Azure CLI to create a queue with a single command.

# Log in to your Azure account (if not already logged in)
# az login

# Set your subscription (if you have multiple)
# az account set --subscription "Your Subscription Name"

# Create a queue
az storage queue create \
    --name my-cli-queue \
    --account-name your-storage-account-name \
    --account-key "YOUR_STORAGE_ACCOUNT_KEY"

# Or using a connection string
# az storage queue create \
#    --name my-cli-queue \
#    --connection-string "YOUR_AZURE_STORAGE_CONNECTION_STRING"

Create a Queue using Azure PowerShell

Use the following PowerShell command to create a queue.

# Connect to your Azure account (if not already connected)
# Connect-AzAccount

# Set your subscription (if you have multiple)
# Set-AzContext -SubscriptionId "Your Subscription ID"

# Create a queue
New-AzStorageQueue -Name "my-powershell-queue" -Context (New-AzStorageContext -StorageAccountName "your-storage-account-name" -StorageAccountKey "YOUR_STORAGE_ACCOUNT_KEY")

# Or using a connection string
# New-AzStorageQueue -Name "my-powershell-queue" -ConnectionString "YOUR_AZURE_STORAGE_CONNECTION_STRING"
Note: Replace placeholders like your-storage-account-name, YOUR_STORAGE_ACCOUNT_KEY, and YOUR_AZURE_STORAGE_CONNECTION_STRING with your actual Azure Storage details.