(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to create an Azure Function Queue-trigger in C#: step by step

João Barros 17 de September de 2026 4 min read

This tutorial shows how to create an Azure Function with a trigger for Azure Storage Queue in C# to process messages asynchronously. It is useful to decouple components, handle load spikes, and reliably integrate systems.

Prerequisites

  • Azure account with permissions to create resources.
  • Azure CLI installed and authenticated (az login).
  • Visual Studio Code or Visual Studio with .NET SDK 7+.
  • Azure Functions Core Tools (v4) to run locally.
  • Azure Functions extension in VS Code (optional).

Step 1: Create a Storage Account and a Queue

The Azure Function will read messages from an Azure Storage Queue. First we create the Storage Account and the Queue in the portal or via CLI. We use the CLI because it is repeatable and fast.

az group create --name rg-func-queue --location westeurope
az storage account create --name funcqueuestorage$RANDOM --resource-group rg-func-queue --location westeurope --sku Standard_LRS --kind StorageV2
# Obter connection string
CONN=$(az storage account show-connection-string --name funcqueuestorage$RANDOM --resource-group rg-func-queue -o tsv)
# Criar a queue
az storage queue create --name myqueue --connection-string "$CONN"

Step 2: Create the Azure Functions project in C#

We create a Functions project with a Queue trigger. We choose the QueueTrigger template and the binding for Storage Queue.

dotnet new console -n FuncQueueApp -o FuncQueueApp
cd FuncQueueApp
func init --worker-runtime dotnet
func new --template "Queue trigger" --name QueueProcessor

The generated file QueueProcessor.cs has a Run method that receives a string message and an ILogger. We will adjust the queue binding via application settings.

Step 3: Configure local.settings.json and the Storage connection

Locally we set AzureWebJobsStorage to point to the Storage Account. This allows testing the Function with the created queue.

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=SEU_ACCOUNT;AccountKey=SEU_KEY;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

Replace SEU_ACCOUNT and SEU_KEY with the values obtained with az storage account keys list or by using the connection string CONN from Step 1.

Step 4: Implement the processing logic

We edit QueueProcessor.cs to process the message. We keep the example simple: deserialize JSON and log.

using System.Text.Json;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public class QueueProcessor
{
    [FunctionName("QueueProcessor")]
    public void Run([QueueTrigger("myqueue", Connection = "AzureWebJobsStorage")] string myQueueItem, ILogger log)
    {
        try
        {
            var obj = JsonSerializer.Deserialize(myQueueItem);
            log.LogInformation($"Processed message: {obj}");
            // TODO: add business logic (database, HTTP call, etc.)
        }
        catch (Exception ex)
        {
            log.LogError(ex, "Erro a processar mensagem");
            throw; // rethrow to let the message remain in the queue or go to the poison queue
        }
    }
}

Step 5: Test locally

Run the Function locally and put a message in the queue. Use Azure Storage Explorer or the CLI to enqueue a JSON message.

func start
# Noutra terminal, enviar mensagem
az storage message put --queue-name myqueue --content '{"id":1,"name":"teste"}' --connection-string "$CONN"

Check the func start logs to see the message being processed.

Step 6: Deploy to Azure (Function App)

Create a Function App in Azure and publish the code. Here we use the CLI and publish via zip deploy with func.

az functionapp plan create --name plan-func --resource-group rg-func-queue --location westeurope --number-of-workers 1 --sku EP1
az functionapp create --resource-group rg-func-queue --consumption-plan-location westeurope --name myfuncqueueapp$RANDOM --storage-account funcqueuestorage$RANDOM --runtime dotnet
# Publicar
func azure functionapp publish myfuncqueueapp$RANDOM
# Definir setting AzureWebJobsStorage no Function App com a connection string
az functionapp config appsettings set --name myfuncqueueapp$RANDOM --resource-group rg-func-queue --settings AzureWebJobsStorage="$CONN"

After publishing the Function App will be reading messages from the queue in Azure.

Verify the result

To confirm everything is fine, send a message to the queue and view the Function App logs. Use Azure Portal > Function App > Functions > QueueProcessor > Monitor to see executions. Also check if there are no messages in the queue or if failed messages moved to the poison queue (myqueue-poison).

Conclusion

You now have an Azure Function Queue-trigger in C# processing messages from Azure Storage Queue locally and in Azure. Next steps: add retry/backoff, integrate with Azure Service Bus if you need advanced features, and create automated tests. Tip: monitor with Application Insights to diagnose issues and common errors such as wrong connection string or dependency timeouts.