Azure Functions Queue Output Bindings

Overview

Queue output bindings allow your Azure Function to write messages to an Azure Queue Storage queue. This is a common pattern for decoupling services, enabling asynchronous processing, and building event-driven architectures.

Supported Queue Types

Azure Functions supports output bindings for:

Configuration

Output bindings are configured in your function's function.json file. The binding type is typically queue for Azure Queue Storage or serviceBus for Service Bus.

Azure Queue Storage Example (function.json)


{
  "scriptFile": "run.py",
  "bindings": [
    {
      "name": "msg",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "myqueue-items",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "outputQueueItem",
      "type": "queue",
      "direction": "out",
      "queueName": "myoutputqueue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
            

Azure Service Bus Queue Example (function.json)


{
  "scriptFile": "run.csx",
  "bindings": [
    {
      "name": "inputQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "input-queue",
      "connection": "ServiceBusConnectionString"
    },
    {
      "name": "outputServiceBusQueue",
      "type": "serviceBus",
      "direction": "out",
      "queueName": "processed-items-queue",
      "connection": "ServiceBusConnectionString"
    }
  ]
}
            

Using the Output Binding in Code

The way you interact with the output binding depends on your chosen language.

C# Example

In C#, the output binding is typically represented by an out parameter, often of type IAsyncCollector<T> or a specific SDK type like string.


using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public static class QueueOutputBindingExample
{
    [FunctionName("QueueOutputTrigger")]
    public static void Run(
        [QueueTrigger("myqueue-items")] string myQueueItem,
        [Queue("myoutputqueue")] out string outputQueueItem,
        ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
        outputQueueItem = $"Processed: {myQueueItem}";
        log.LogInformation($"Message sent to output queue: {outputQueueItem}");
    }
}
            

Python Example

In Python, the output binding is passed as an argument to your function and you use its .set() method.


import logging
import azure.functions as func

def main(msg: func.QueueMessage, outputQueueItem: func.Out[str]) -> None:
    logging.info('Python queue trigger function processed a message: %s',
                 msg.get_body().decode('utf-8'))

    message_body = msg.get_body().decode('utf-8')
    processed_message = f"Processed: {message_body}"
    outputQueueItem.set(processed_message)
    logging.info('Message sent to output queue: %s', processed_message)
            

JavaScript Example

In JavaScript, the output binding is available as a parameter and you assign to it.


module.exports = async function (context, myQueueItem) {
    context.log('JavaScript queue trigger function processed work item', myQueueItem);

    const processedMessage = `Processed: ${myQueueItem}`;
    context.bindings.outputQueueItem = processedMessage;
    context.log('Message sent to output queue:', processedMessage);
};
            

Common Scenarios

Best Practices