azureazure-functionsazureservicebusazure-queues

Azure Queues: Delay between retries (Azure Function)


I'm using Azure Queues to save failed messages.

Each message have to be retried by an Azure Function 10 times before it is discarded.

How can I establish the delay between each retry? (if I use standard behaviour the message is retried 10 times in less than a second)


Solution

  • Your question does not make it 100% clear if you are using queues in Azure Storage or Azure Service Bus. If you are using Azure Storage Queues:

    You can leverage visibilityTimeout to configure the time between retries. Internally, this will lock the message to the current consumer for a specified amount of time. In case of error, the message will not be deleted and after the timeout Azure Queue makes the message available again to any available consumers.

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue?tabs=in-process%2Cextensionv5%2Cextensionv3&pivots=programming-language-csharp#host-json

    {
        "version": "2.0",
        "extensions": {
            "queues": {
                "maxPollingInterval": "00:00:02",
                "visibilityTimeout" : "00:00:30",
                "batchSize": 16,
                "maxDequeueCount": 5,
                "newBatchThreshold": 8,
                "messageEncoding": "base64"
            }
        }
    }
    

    visibilityTimeout The time interval between retries when processing of a message fails.

    See also this answer for some more details: Azure function visibilityTimeout