Microsoft.Azure.WebJobs.Extensions.Storage.Queues 5.1.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET Standard 2.0
dotnet add package Microsoft.Azure.WebJobs.Extensions.Storage.Queues --version 5.1.0
NuGet\Install-Package Microsoft.Azure.WebJobs.Extensions.Storage.Queues -Version 5.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage.Queues" Version="5.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.Azure.WebJobs.Extensions.Storage.Queues --version 5.1.0
#r "nuget: Microsoft.Azure.WebJobs.Extensions.Storage.Queues, 5.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Microsoft.Azure.WebJobs.Extensions.Storage.Queues as a Cake Addin
#addin nuget:?package=Microsoft.Azure.WebJobs.Extensions.Storage.Queues&version=5.1.0

// Install Microsoft.Azure.WebJobs.Extensions.Storage.Queues as a Cake Tool
#tool nuget:?package=Microsoft.Azure.WebJobs.Extensions.Storage.Queues&version=5.1.0

Azure WebJobs Storage Queues client library for .NET

This extension provides functionality for accessing Azure Storage Queues in Azure Functions.

Getting started

Install the package

Install the Storage Queues extension with NuGet:

dotnet add package Azure.WebJobs.Extensions.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 <your-resource-name> --resource-group <your-resource-group-name> --location westus --sku Standard_LRS

Authenticate the client

In order for the extension to access Queues, you will need the connection string which can be found in the Azure Portal or by using the Azure CLI snippet below.

az storage account show-connection-string -g <your-resource-group-name> -n <your-resource-name>

The connection string can be supplied through AzureWebJobsStorage app setting.

Key concepts

Using Queue trigger

The queue storage trigger runs a function as messages are added to Azure Queue storage.

Please follow the tutorial to learn about how to listen to queues in Azure Functions.

Using Queue binding

Azure Functions can create new Azure Queue storage messages by setting up an output binding.

Please follow the binding tutorial to learn about using this extension for producing messages into queues in Azure Functions.

Examples

Listening to queue

The following set of examples shows how to receive and react to messages that are being added to the queue.

Binding queue message to string
public static class QueueTriggerFunction_String
{
    [FunctionName("QueueTriggerFunction")]
    public static void Run(
        [QueueTrigger("sample-queue")] string message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue, content={content}", message);
    }
}
Binding queue message to BinaryData
public static class QueueTriggerFunction_BinaryData
{
    [FunctionName("QueueTriggerFunction")]
    public static void Run(
        [QueueTrigger("sample-queue")] BinaryData message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue, content={content}", message.ToString());
    }
}
Binding queue message to QueueMessage
public static class QueueTriggerFunction_QueueMessage
{
    [FunctionName("QueueTriggerFunction")]
    public static void Run(
        [QueueTrigger("sample-queue")] QueueMessage message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue, content={content}", message.Body.ToString());
    }
}
Binding queue message to custom type
public static class QueueTriggerFunction_CustomObject
{
    public class CustomMessage
    {
        public string Content { get; set; }
    }

    [FunctionName("QueueTriggerFunction")]
    public static void Run(
        [QueueTrigger("sample-queue")] CustomMessage message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue, content={content}", message.Content);
    }
}
Binding queue message to JObject
public static class QueueTriggerFunction_JObject
{
    [FunctionName("QueueTriggerFunction")]
    public static void Run(
        [QueueTrigger("sample-queue")] JObject message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue, content={content}", message["content"]);
    }
}

Publishing messages to queue

The following set of examples shows how to add messages to queue by using Queue attribute.

The QueueTrigger is used just for sample completeness, i.e. any other trigger mechanism can be used instead.

Publishing message as string
public static class QueueSenderFunction_String_Return
{
    [FunctionName("QueueFunction")]
    [return: Queue("sample-queue-2")]
    public static string Run(
        [QueueTrigger("sample-queue-1")] string message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue-1, content={content}", message);
        logger.LogInformation("Dispatching message to sample-queue-2");
        return message;
    }
}
Publishing message as BinaryData
public static class QueueSenderFunction_BinaryData_Return
{
    [FunctionName("QueueFunction")]
    [return: Queue("sample-queue-2")]
    public static BinaryData Run(
        [QueueTrigger("sample-queue-1")] BinaryData message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue-1, content={content}", message.ToString());
        logger.LogInformation("Dispatching message to sample-queue-2");
        return message;
    }
}
Publishing message as QueueMessage
public static class QueueSenderFunction_QueueMessage_Return
{
    [FunctionName("QueueFunction")]
    [return: Queue("sample-queue-2")]
    public static QueueMessage Run(
        [QueueTrigger("sample-queue-1")] QueueMessage message,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue-1, content={content}", message.Body.ToString());
        logger.LogInformation("Dispatching message to sample-queue-2");
        return message;
    }
}
Publishing message as custom type through out parameter
public static class QueueSenderFunction_CustomObject_OutParamter
{
    public class CustomMessage
    {
        public string Content { get; set; }
    }

    [FunctionName("QueueFunction")]
    public static void Run(
        [QueueTrigger("sample-queue-1")] CustomMessage incomingMessage,
        [Queue("sample-queue-2")] out CustomMessage outgoingMessage,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue-1, content={content}", incomingMessage.Content);
        logger.LogInformation("Dispatching message to sample-queue-2");
        outgoingMessage = incomingMessage;
    }
}
Publishing message as custom type through collector
public static class QueueSenderFunction_CustomObject_Collector
{
    public class CustomMessage
    {
        public string Content { get; set; }
    }

    [FunctionName("QueueFunction")]
    public static void Run(
        [QueueTrigger("sample-queue-1")] CustomMessage incomingMessage,
        [Queue("sample-queue-2")] ICollector<CustomMessage> collector,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue-1, content={content}", incomingMessage.Content);
        logger.LogInformation("Dispatching message to sample-queue-2");
        collector.Add(incomingMessage);
    }
}

Accessing queue properties

public static class Function_BindingToQueueClient
{
    [FunctionName("QueueFunction")]
    public static async Task Run(
        [QueueTrigger("sample-queue")] string message,
        [Queue("sample-queue")] QueueClient queueClient,
        ILogger logger)
    {
        logger.LogInformation("Received message from sample-queue, content={content}", message);
        QueueProperties queueProperties = await queueClient.GetPropertiesAsync();
        logger.LogInformation("There are approximatelly {count} messages", queueProperties.ApproximateMessagesCount);
    }
}

Configuring the extension

Please refer to sample functions app.

Troubleshooting

Please refer to Monitor Azure Functions for troubleshooting guidance.

Next steps

Read the introduction to Azure Function or creating an Azure Function guide.

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.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Microsoft.Azure.WebJobs.Extensions.Storage.Queues:

Package Downloads
Microsoft.Azure.WebJobs.Extensions.Storage The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

This extension adds bindings for Storage

SimpleMessageBus.Dispatch

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Microsoft.Azure.WebJobs.Extensions.Storage.Queues:

Repository Stars
Azure/azure-functions-kafka-extension
Kafka extension for Azure Functions
Version Downloads Last updated
5.1.0 48,675 2/22/2023
5.1.0-beta.1 630 2/8/2023
5.0.1 2,577,869 5/3/2022
5.0.0 3,056,533 10/26/2021
5.0.0-beta.5 104,721 7/9/2021
5.0.0-beta.4 32,205 5/18/2021
5.0.0-beta.3 13,473 3/10/2021
5.0.0-beta.2 18,932 2/10/2021
5.0.0-beta.1 28,431 11/10/2020