Queue Storage Output Bindings

Queue storage output bindings enable your Azure Functions to write messages to an Azure Queue Storage queue. This is a common pattern for decoupling services, creating asynchronous workflows, and enabling background processing.

Supported Languages

Queue output bindings are supported across most Azure Functions runtimes, including C#, JavaScript, Python, PowerShell, and Java.

Configuration

To configure a queue output binding, you typically define it in your function's function.json file (for JavaScript, Python, PowerShell, Java) or using attributes in your code (for C#).

Example: function.json


{
  "scriptFile": "index.js",
  "bindings": [
    {
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "outputQueueItem",
      "type": "queue",
      "direction": "out",
      "queueName": "my-output-queue",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    }
  ]
}
            

Example: C# Attributes


using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace MyFunctions
{
    public class QueueOutputFunction
    {
        [Function("QueueOutputFunction")]
        [QueueOutput("my-output-queue")] // Output binding configuration
        public string Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
            FunctionContext context)
        {
            var logger = context.GetLogger();
            logger.LogInformation("HTTP trigger function processed a request.");

            string message = "Hello from Azure Functions output binding!";
            logger.LogInformation($"Sending message to queue: {message}");

            return message; // The return value is sent to the queue
        }
    }
}
            

Binding Details

How it Works

When your function executes, the value returned by the function (or assigned to the output binding parameter in some languages) is automatically sent as a message to the specified Azure Queue Storage queue. This happens after your function code has successfully completed.

Note:

If your function throws an exception, the message will not be sent to the queue.

Common Use Cases

Monitoring

You can monitor the messages in your queue and the execution of your functions using the Azure portal, Azure Monitor, and Application Insights.

Example Workflow

  1. An HTTP trigger function is invoked.
  2. The function processes some data.
  3. The function returns a string or object that is automatically serialized and sent as a message to a configured Azure Queue Storage queue.
  4. A separate queue-triggered function can then pick up this message for further processing.

Related Topics