Queue Bindings
Queue bindings in Azure Functions allow you to trigger functions based on messages arriving in a queue or to output messages to a queue.
Overview
Queue bindings integrate your functions with Azure Storage Queues and other queueing services. They offer a declarative way to handle queue operations, simplifying your function code.
You can use queue bindings in two primary ways:
- Trigger: A function is executed when a new message is added to a specified queue.
- Output: A function writes a message to a specified queue.
Trigger Binding
The queue trigger for Azure Functions listens for new messages on an Azure Storage Queue. When a message appears, the function is executed, and the message content is passed as input to the function.
Configuration (function.json)
            {
  "scriptFile": "index.js",
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "my-input-queue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}Example (JavaScript)
module.exports = async function (context, myQueueItem) {
    context.log('JavaScript queue trigger function processed work item', myQueueItem);
    // Process the message content (myQueueItem) here
    context.log(`Message content: ${myQueueItem}`);
};Trigger Binding Properties
| Property | Description | Required | 
|---|---|---|
| name | The name of the parameter in your function code that receives the queue message. | Yes | 
| type | Must be queueTrigger. | Yes | 
| direction | Must be infor a trigger. | Yes | 
| queueName | The name of the queue to monitor. | Yes | 
| connection | The name of an app setting containing the queue storage connection string. Defaults to AzureWebJobsStorage. | No | 
                Important: When a queue trigger function processes a message, it automatically attempts to delete the message from the queue upon successful completion. If the function fails, the message remains in the queue for potential reprocessing.
            
            Output Binding
The queue output binding allows you to send messages to an Azure Storage Queue from your function.
Configuration (function.json)
            {
  "scriptFile": "index.js",
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "my-input-queue",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "outputQueueItem",
      "type": "queue",
      "direction": "out",
      "queueName": "my-output-queue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}Example (JavaScript)
module.exports = async function (context, myQueueItem) {
    context.log('JavaScript queue trigger function processed work item', myQueueItem);
    const messageToSend = `Processed: ${myQueueItem}`;
    context.log(`Sending message to output queue: ${messageToSend}`);
    // Set the output binding to send the message
    context.bindings.outputQueueItem = messageToSend;
};Output Binding Properties
| Property | Description | Required | 
|---|---|---|
| name | The name of the parameter in your function code that you assign a value to send to the queue. | Yes | 
| type | Must be queue. | Yes | 
| direction | Must be outfor an output binding. | Yes | 
| queueName | The name of the queue to send messages to. | Yes | 
| connection | The name of an app setting containing the queue storage connection string. Defaults to AzureWebJobsStorage. | No | 
                You can bind to a collection (e.g., 
            byte[], string[], MyObject[]) for output to send multiple messages in one go.
            Advanced Scenarios
- Poison Queue Handling: Configure behavior for messages that repeatedly cause function failures.
- Batch Processing: For some triggers, functions can process multiple messages at once.
- Queue Message Content: The content of the queue message can be a string, JSON object, or binary data.