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:
- Fetching related data from Blob Storage.
- Retrieving configuration or lookup data from Table Storage.
- Accessing documents from Cosmos DB.
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:
- msg(or- queueMessagein C#) is the queue message itself.
- myBlobis the input binding.
- The pathproperty in the binding configuration is crucial. It uses expressions (e.g.,{queueMessageProperty}) to dynamically specify the resource to retrieve. The expression typically references a property or value within the incoming queue message.
- connectionspecifies the application setting that contains the connection string for the storage account.
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.
Common Scenarios and Best Practices
- Data Enrichment: Use input bindings to fetch supplementary data that your function needs to process the queue message effectively, rather than making multiple SDK calls.
- Conditional Logic: Input bindings can be used to retrieve configuration or metadata that influences the function's execution logic.
- Error Handling: Ensure your input binding paths are robust. If a referenced blob or document doesn't exist, the function might fail. Consider using default values or implementing specific error handling.
- Performance: While convenient, be mindful of the latency introduced by fetching external data. For performance-critical operations, optimize your binding configurations or consider alternative approaches.
Next Steps
Explore other Azure Functions binding types: