Queue Storage Bindings
Azure Functions provides powerful integration with Azure Storage Queue service through input and output bindings. These bindings simplify the process of sending and receiving messages to and from Azure Queues, allowing you to focus on your business logic.
A queue trigger starts your function when a new message is added to an Azure Storage Queue. The message content is passed to your function as input.
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace MyFunctions
{
public static class QueueTriggerFunction
{
[FunctionName("QueueTriggerCSharp")]
public static void Run(
[QueueTrigger("myqueue-items")] string myQueueItem,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}
}
}
module.exports = async function (context, myQueueItem) {
context.log('JavaScript queue trigger function processed work item', myQueueItem);
};
A queue output binding allows your function to send messages to an Azure Storage Queue.
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace MyFunctions
{
public static class QueueOutputFunction
{
[FunctionName("QueueOutputCSharp")]
public static void Run(
[QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string myQueueItem,
[Queue("outputqueue", Connection = "AzureWebJobsStorage")] out string outputQueueItem,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
outputQueueItem = $"Processed item: {myQueueItem}";
}
}
}
module.exports = async function (context, req) {
const message = req.body || "default message";
context.bindings.outputQueueItem = message;
context.log('JavaScript queue output processed work item', message);
};
Queue bindings offer several configuration options to customize their behavior.
| Attribute | Description | Required |
|---|---|---|
| queueName | The name of the Azure Storage Queue. | Yes |
| connection | The name of an app setting that contains the Azure Storage connection string. If not specified, the default connection string defined in AzureWebJobsStorage is used. | No |
| accessRights | (For output bindings) Specifies the access rights. Can be Read, Write, or Full. Defaults to Write. | No |
| cardinality | (For trigger bindings) Controls whether the binding delivers a single message or a batch of messages. Options are One or Many. Defaults to One. | No |
Queue bindings are excellent for implementing asynchronous processing and decoupling different parts of your application. For example, a web API can place a request message onto a queue, and a separate Azure Function can process that request asynchronously.
For more advanced scenarios, consider using Azure Service Bus bindings.