Home > Software engineering >  Azure Service Bus Retry Options Not Working (v5.2.0)
Azure Service Bus Retry Options Not Working (v5.2.0)

Time:03-05

I'm using version 5.2.0 of the Microsoft.Azure.WebJobs.Extensions.ServiceBus package in my Azure Function. According to the docs here the new version supports automatic retry on failed operations. This is my host.json:

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "clientRetryOptions": {
        "mode": "Exponential",
        "tryTimeout": "00:02:00",
        "delay": "00:00:02.00",
        "maxDelay": "00:30:00",
        "maxRetries": 10
      }
    }
  }
}

Which - apart from the time values - is exactly the same as in the docs. In my Function that is triggered by a ServiceBusTrigger I throw an exception under certain circumstances. I want the message to be delayed, as is described in the documentation. But it is put back at the head of the queue and retried immediately, with no delay. I've spent 2 working days on this, and the mish-mash of versions, incorrect documentation, and examples I've found online, I've tried all manner of permutations, but I just cannot get this to work.

I just can't see the wood for the trees, any longer. Can anyone see what I'm doing wrong?

CodePudding user response:

Seems this question was asked and answered here. Seems that retry only applies to certain errors, namely transient, that it deems is retriable.

CodePudding user response:

The options that you're configuring govern the implicit retry behavior of the Service Bus clients used by the Function bindings. When reading or publishing a message fails due to an error that is deemed transient, these settings are applied to client retries. This flow is invisible to your Function, other than being observable by read/publish taking longer to complete than normal.

Exceptions in your Function code are not governed by these settings. These types of exceptions are governed by the Functions error handling and retries configuration.

CodePudding user response:

Like already mentioned in the other answers, these retry options only apply to internal (transient) exceptions. What you need can be achieved by the new retry policies (preview):

[FunctionName("EventHubTrigger")]
[ExponentialBackoffRetry(5, "00:00:04", "00:15:00")]
public static async Task Run([EventHubTrigger("myHub", Connection = "EventHubConnection")] EventData[] events, ILogger log)
{
// ...
}

Alternatively, specifically for ServiceBus you can achieve a similar behavior by disabling auto-complete and leveraging the lock duration property on the queue. The number of retries can be controlled by using the max delivery count.

  • Related