Azure Documentation

Microsoft Azure

Azure Storage Queues

Azure Storage Queues is a service that provides reliable messaging for decoupling application components. It allows you to manage and scale workloads by making it easier to develop and operate applications that need to communicate asynchronously.

What are Azure Storage Queues?

Azure Queues is a REST-based service that allows you to enqueue messages and then process them asynchronously. Each message can be up to 64 KB in size. A queue can contain an unlimited number of messages, up to the limit of the storage account's total capacity.

Key Benefits:
  • Decoupling: Components can communicate without being directly connected.
  • Scalability: Easily scale different parts of your application independently.
  • Reliability: Messages are persisted until successfully processed.
  • Asynchronous Operations: Improve application responsiveness by offloading long-running tasks.

Core Concepts

Messages

A message in Azure Queues is a block of data, up to 64 KB, that you want to store for later processing. Messages are stored in UTF-8 encoded text. If the message content is binary, it should be Base64 encoded before being added to the queue.

Queues

A queue is a collection of messages. Each queue must have a unique name within the storage account. Queue names must be lowercase ASCII letters, numbers, and hyphens. They must start and end with a letter or number, and cannot contain consecutive hyphens.

Message Visibility

When a message is retrieved from a queue, it becomes invisible to other consumers for a specified period (the visibility timeout). If the message is not deleted within this timeout, it becomes visible again and can be dequeued by another consumer. This ensures that messages are processed reliably, even if a consumer fails.

Common Use Cases

  • Background Job Processing: Offload computationally intensive tasks to background workers.
  • Order Processing: Handle e-commerce orders asynchronously.
  • Data Ingestion: Collect and process large volumes of data from various sources.
  • Buffering: Smooth out spikes in application traffic.

Getting Started

To get started with Azure Storage Queues, you'll need an Azure Storage account. You can create one through the Azure portal, Azure CLI, or Azure PowerShell.

Creating a Queue (Azure CLI Example)


az storage queue create \
    --name myqueue \
    --account-name mystorageaccount \
    --account-key YOUR_STORAGE_ACCOUNT_KEY
                

Adding a Message (Azure SDK Example - Node.js)


const { QueueServiceClient } = require("@azure/storage-queue");

async function sendMessage() {
    const connectionString = "YOUR_CONNECTION_STRING"; // Or use account name/key
    const queueServiceClient = QueueServiceClient.fromConnectionString(connectionString);
    const queueClient = queueServiceClient.getQueueClient("myqueue");

    await queueClient.sendMessage("Hello, Azure Queues!");
    console.log("Message sent.");
}

sendMessage().catch(error => console.error(error));
                

Retrieving and Processing Messages

You typically retrieve messages in a loop, process them, and then delete them upon successful processing. If processing fails, you can choose to make the message visible again or move it to a poison queue.

Tip: Use the popReceipt obtained when retrieving a message to delete or update it.

Learn More