Queue Trigger Input Bindings

This document details how to configure and use input bindings with Azure Queue Storage triggers in Azure Functions.

Introduction

Queue Storage triggers are a fundamental part of Azure Functions, enabling event-driven processing of messages. While the primary trigger mechanism is for receiving messages from a queue, input bindings allow your function to easily access additional data from other Azure services when processing a queue message.

This binding allows you to retrieve information related to the queue message being processed, such as metadata or related data from other services. This can reduce the need for manual SDK calls within your function code.

Supported Input Bindings with Queue Triggers

When a function is triggered by a queue message, you can use various input bindings to fetch additional data. The most common scenarios include:

Configuration

Input bindings are configured in your function's function.json file or using attributes in languages like C#.

function.json Example

This example shows a function triggered by a queue message, with an input binding to retrieve a blob. The blob name is derived from a property within the queue message.


{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "msg",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "myqueue-items",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "myBlob",
      "type": "blob",
      "direction": "in",
      "path": "mycontainer/{queueMessageProperty}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
            

C# Attributes Example


using Microsoft.Azure.WebJobs;

public static class QueueTriggerWithInput
{
    public static void Run(
        [QueueTrigger("myqueue-items")] string queueMessage,
        [Blob("mycontainer/{queueMessageProperty}", Connection = "AzureWebJobsStorage")] Stream myBlob,
        ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed: {queueMessage}");
        // Access the blob content via the 'myBlob' parameter
        // ...
    }
}
            

Binding Parameters

In the examples above:

Accessing Queue Message Properties

The power of input bindings with queue triggers often lies in their ability to dynamically reference parts of the queue message. For example, if your queue message is a JSON object, you can access its properties.

Example JSON Queue Message:


{
  "fileName": "report.pdf",
  "timestamp": "2023-10-27T10:30:00Z",
  "payload": {
    "data": "..."
  }
}
            

You could then configure an input binding to use fileName:


{
  "name": "msg",
  "type": "queueTrigger",
  "direction": "in",
  "queueName": "my-json-queue",
  "connection": "AzureWebJobsStorage"
},
{
  "name": "configFile",
  "type": "blob",
  "direction": "in",
  "path": "config-files/{fileName}.json",
  "connection": "AzureWebJobsStorage"
}
            

This would attempt to retrieve a blob named report.pdf.json from the config-files container.

Note: The availability of specific queue message properties for binding expressions depends on the format of your queue message (e.g., plain text, JSON, XML). For structured messages like JSON, Azure Functions can often parse them to extract properties.

Common Scenarios and Best Practices

Tip: For more complex scenarios or when dealing with highly variable message structures, consider retrieving the entire queue message and then programmatically fetching related data using the Azure SDKs.

Next Steps

Explore other Azure Functions binding types: