Azure.Storage.Queues 12.18.0

Azure Storage Queues client library for .NET

Server Version: 2021-02-12, 2020-12-06, 2020-10-02, 2020-08-04, 2020-06-12, 2020-04-08, 2020-02-10, 2019-12-12, 2019-07-07, and 2019-02-02

Azure Queue storage is a service for storing large numbers of messages that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS. A single queue message can be up to 64 KB in size, and a queue can contain millions of messages, up to the total capacity limit of a storage account.

Source code | Package (NuGet) | API reference documentation | REST API documentation | Product documentation

Getting started

Install the package

Install the Azure Storage Queues client library for .NET with NuGet:

dotnet add package Azure.Storage.Queues

Prerequisites

You need an Azure subscription and a Storage Account to use this package.

To create a new Storage Account, you can use the Azure Portal, Azure PowerShell, or the Azure CLI. Here's an example using the Azure CLI:

az storage account create --name MyStorageAccount --resource-group MyResourceGroup --location westus --sku Standard_LRS

Authenticate the client

In order to interact with the Azure Queue Storage service, you'll need to create an instance of the QueueClient class. The Azure Identity library makes it easy to add Azure Active Directory support for authenticating Azure SDK clients with their corresponding Azure services.

// Create a QueueClient that will authenticate through Active Directory
Uri queueUri = new Uri("https://MYSTORAGEACCOUNT.queue.core.windows.net/QUEUENAME");
QueueClient queue = new QueueClient(queueUri, new DefaultAzureCredential());

Learn more about enabling Azure Active Directory for authentication with Azure Storage in our documentation and our samples.

Key concepts

Common uses of Queue storage include:

  • Creating a backlog of work to process asynchronously
  • Passing messages between different parts of a distributed application

Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.

Additional concepts

Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime

Examples

Send messages

// We'll need a connection string to your Azure Storage account.
// You can obtain your connection string from the Azure Portal
// (click Access Keys under Settings in the Portal Storage account
// blade) or using the Azure CLI with:
//
//     az storage account show-connection-string --name <account_name> --resource-group <resource_group>
//
// You would normally provide the connection string to your
// application using an environment variable.
string connectionString = "<connection_string>";

// Name of the queue we'll send messages to
string queueName = "sample-queue";

// Get a reference to a queue and then create it
QueueClient queue = new QueueClient(connectionString, queueName);
queue.Create();

// Send a message to our queue
queue.SendMessage("Hello, Azure!");

Receive messages

// We'll need a connection string to your Azure Storage account.
string connectionString = "<connection_string>";

// Name of an existing queue we'll operate on
string queueName = "sample-queue";

// Get a reference to a queue and then fill it with messages
QueueClient queue = new QueueClient(connectionString, queueName);
queue.SendMessage("first");
queue.SendMessage("second");
queue.SendMessage("third");

// Get the next messages from the queue
foreach (QueueMessage message in queue.ReceiveMessages(maxMessages: 10).Value)
{
    // "Process" the message
    Console.WriteLine($"Message: {message.Body}");

    // Let the service know we're finished with the message and
    // it can be safely deleted.
    queue.DeleteMessage(message.MessageId, message.PopReceipt);
}

Async APIs

We fully support both synchronous and asynchronous APIs.

// We'll need a connection string to your Azure Storage account.
string connectionString = "<connection_string>";

// Name of the queue we'll send messages to
string queueName = "sample-queue";

// Get a reference to a queue and then create it
QueueClient queue = new QueueClient(connectionString, queueName);
await queue.CreateAsync();

// Send a message to our queue
await queue.SendMessageAsync("Hello, Azure!");

Message encoding

This version of library does not encode message by default. V11 and prior versions as well as Azure Functions use base64-encoded messages by default. Therefore it's recommended to use this feature for interop scenarios.

QueueClientOptions queueClientOptions = new QueueClientOptions()
{
    MessageEncoding = QueueMessageEncoding.Base64
};

QueueClient queueClient = new QueueClient(connectionString, queueName, queueClientOptions);

Troubleshooting

All Azure Storage Queue service operations will throw a RequestFailedException on failure with helpful ErrorCodes. Many of these errors are recoverable.

// We'll need a connection string to your Azure Storage account.
string connectionString = "<connection_string>";

// Name of an existing queue we'll operate on
string queueName = "sample-queue";

try
{
    // Try to create a queue that already exists
    QueueClient queue = new QueueClient(connectionString, queueName);
    queue.Create();
}
catch (RequestFailedException ex)
    when (ex.ErrorCode == QueueErrorCode.QueueAlreadyExists)
{
    // Ignore any errors if the queue already exists
}

Next steps

Get started with our Queue samples:

  1. Hello World: Enqueue, Dequeue, Peek, and Update queue messages (or asynchronously)
  2. Auth: Authenticate with connection strings, shared keys, shared access signatures, and Azure Active Directory.

Contributing

See the Storage CONTRIBUTING.md for details on building, testing, and contributing to this library.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Showing the top 20 packages that depend on Azure.Storage.Queues.

Packages Downloads
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
12
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
10
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
9
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
8
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
7
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
6
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
5
Microsoft.Azure.Kusto.Ingest
Programmatically ingest data into Kusto
4

https://github.com/Azure/azure-sdk-for-net/blob/Azure.Storage.Queues_12.18.0/sdk/storage/Azure.Storage.Queues/CHANGELOG.md

.NET 6.0

.NET Standard 2.0

.NET Standard 2.1

Version Downloads Last updated
12.21.0 1 11/15/2024
12.21.0-beta.2 0 10/10/2024
12.21.0-beta.1 0 10/08/2024
12.20.1 0 10/11/2024
12.20.0 0 09/19/2024
12.20.0-beta.1 1 08/09/2024
12.19.1 2 07/27/2024
12.19.0 1 07/23/2024
12.19.0-beta.1 2 06/24/2024
12.18.0 3 05/28/2024
12.18.0-beta.2 4 04/28/2024
12.18.0-beta.1 4 04/28/2024
12.17.1 4 04/28/2024
12.17.0 5 04/28/2024
12.17.0-beta.1 5 04/28/2024
12.16.0 5 04/28/2024
12.16.0-beta.1 4 04/28/2024
12.15.0 4 04/28/2024
12.15.0-beta.1 4 04/28/2024
12.14.0 6 04/28/2024
12.14.0-beta.1 4 04/28/2024
12.13.1 4 04/28/2024
12.13.0 6 04/28/2024
12.13.0-beta.1 5 04/28/2024
12.12.0 5 04/28/2024
12.12.0-beta.1 3 04/28/2024
12.11.1 5 04/28/2024
12.11.0 4 04/28/2024
12.11.0-beta.1 3 04/28/2024
12.10.0 6 04/28/2024
12.10.0-beta.1 4 04/28/2024
12.9.0 5 04/05/2024
12.9.0-beta.3 5 04/28/2024
12.9.0-beta.2 4 04/28/2024
12.9.0-beta.1 4 04/28/2024
12.8.0 5 04/29/2024
12.8.0-beta.2 4 04/28/2024
12.8.0-beta.1 5 04/28/2024
12.7.0 5 04/29/2024
12.7.0-beta.4 5 04/28/2024
12.7.0-beta.3 4 04/28/2024
12.7.0-beta.2 5 04/28/2024
12.7.0-beta.1 4 04/28/2024
12.6.2 4 04/29/2024
12.6.1 4 04/29/2024
12.6.0 6 04/29/2024
12.6.0-beta.1 5 04/28/2024
12.5.0 5 04/29/2024
12.5.0-preview.1 4 04/28/2024
12.4.2 4 04/29/2024
12.4.1 5 04/29/2024
12.4.0-preview.6 5 04/28/2024
12.4.0-preview.5 5 04/28/2024
12.4.0-preview.4 5 04/28/2024
12.4.0-preview.1 5 04/28/2024
12.3.2 5 04/29/2024
12.3.1 5 04/29/2024
12.3.0 5 04/29/2024
12.2.0 5 04/29/2024
12.1.1 6 04/29/2024
12.1.0 4 04/29/2024
12.0.0 6 04/29/2024
12.0.0-preview.4 4 04/28/2024
12.0.0-preview.3 5 04/28/2024
12.0.0-preview.2 6 04/28/2024
12.0.0-preview.1 4 04/28/2024
1.0.0-preview.1 4 04/28/2024