I have an Azure function with a servicebustrigger as below
[FunctionName("ServiceBusQueueTriggerCSharp")]
public static void Run(
[ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")]
string myQueueItem,
Int32 deliveryCount,
ILogger log)
{
// Do some stuff with httpclient
}
We are using polly to retry the HTTP call in case of a failure. Polly is configured as part of the DI setup as follows
services.AddHttpClient(ClientNames.HttpClient).SetHandlerLifetime(TimeSpan.FromMinutes(5)).AddPolicyHandler(GetRetryPolicy());
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(1, retryAttempt => TimeSpan.FromSeconds(5 * retryAttempt));
}
I would like the retry delay to be based on "deliveryCount" (the ServiceBus trigger parameter) value instead of retryAttempt which is currently being used.
I'm not able to access deliveryCount during the DI setup phase.
If anyone could provide some guidance on how this can be done, please let me know?