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)
2
Answers
That’s a normal behavior for Azure Functions with Service Bus. If you need to have a delay between the retries, you’ll need to implement a custom logic that either defers the original message and sends a scheduled message with the deferred original message’s sequence number to retrieve it when the scheduled message appears on the queue and processed by the function. Or, alternatively, use a 3rd party library that supports this feature.
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
See also this answer for some more details: Azure function visibilityTimeout