I have the following retry policy which uses Polly.Extensions.Http
:
var retryPolicy = Policy.Handle<BrokenCircuitException>().OrTransientHttpError().WaitAndRetryAsync
(
retryCount: maxRetryCount,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
onRetryAsync: (exception, calculatedWaitDuration, retryCount, context) =>
{
//Code
}
);
I want to wrap the policy with circuit breaker and bulk head policies:
var circuitBreaker = Policy.Handle<HttpRequestException>().CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: maxExceptionsBeforeBreaking,
durationOfBreak: TimeSpan.FromSeconds(circuitBreakDurationSeconds),
onBreak: (exception, timespan, context) =>
{
//Code
},
onReset: (context) =>
{
//Code
}
);
var sharedBulkhead = Policy.BulkheadAsync(
maxParallelization: maxParallelizations,
maxQueuingActions: maxQueuingActions,
onBulkheadRejectedAsync: (context) =>
{
//Code
}
);
I use the following code to wrap the policies together:
Policy.WrapAsync(retryPolicy, circuitBreaker, sharedBulkhead);
This is giving an error:
can not convert from 'Polly.Retry.RetryPolicy<System.Net.Http.HttpResponseMessage>' to 'Polly.IAsyncPolicy'