Up until now, I used Polly's standard CircuitBreaker policy like this:
int retryCount = 2;PolicyBuilder policyBuilder = Policy .HandleInner<WebException>() .Or<WebException>() .Or<TimeoutException>() .Or<TimeoutRejectedException>();AsyncCircuitBreakerPolicy asyncCircuitBreakerPolicy = policyBuilder .CircuitBreakerAsync(1, TimeSpan.FromSeconds(1), OnBreak, OnReset);AsyncRetryPolicy asyncWaitAndRetry = policyBuilder .WaitAndRetryAsync(retryCount, SleepDurationProvider, OnRetry);AsyncPolicyWrap defaultPolicy = Policy.WrapAsync( asyncCircuitBreakerPolicy, asyncWaitAndRetry);
I.e. retry 2 times when an exception is thrown, and after a total of three failures the exception bubbles up to the CircuitBreaker which triggers immediately.
Polly V8 doesn't have this "standard" CircuitBreaker anymore, but something similar to the old "advanced" one. It wants a MinimumThroughput of at least 2, and a failure rate instead of a fixed count. Additionally, it rethrows all Exceptions.
Now I wonder how to migrate to V8. I was thinking about flipping the order of Retry and CircuitBreaker, setting MinimumThroughput = retryCount + 1
and FailureRatio = 1
. But then there's also SamplingDuration
, so I'd need to make that somehow depend on the expected timeouts, plus the waiting time between retries etc.
Is there another approach to do this? Should I just write my own ResilienceStrategy
?