How to filter specific endpoint for retry policy using Polly
All client requests MyServiceHttpClient
will retry. How disable retry policy specific api?
services.AddHttpClient<MyServiceHttpClient>(client =>
{
/* configuration */
})
.AddPolicyHandler((serviceProvider, request) =>
HttpPolicyExtensions.HandleTransientHttpError()
.WaitAndRetryAsync(3,
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
onRetry: (outcome, timespan, retryAttempt, context) =>
{
serviceProvider.GetService<ILogger<MyServiceHttpClient>>()
.LogWarning("Delaying for {delay}ms, then making retry {retry}.", timespan.TotalMilliseconds, retryAttempt);
}
));