Implementing Exponential Retry policy for ServiceB

2019-07-17 02:50发布

I am trying to implement Retry Policy for Service Bus transient error. I want my system to try exponentially like 1s, 2s, 4s, 8s, 16s, 32s, 64s, 128s.

    private int minBackoffDelayInMilliseconds = 2000;
    private int maxBackoffDelayInMilliseconds = 10000;
    private int deltaBackoffInMilliseconds = 2000;

    var defaultPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(new ExponentialBackoff(maxRetries, TimeSpan.FromMilliseconds(minBackoffDelayInMilliseconds), TimeSpan.FromMilliseconds(maxBackoffDelayInMilliseconds), TimeSpan.FromMilliseconds(deltaBackoffInMilliseconds))

Does this look right ? and does this policy affect the system performance ?

1条回答
何必那么认真
2楼-- · 2019-07-17 03:20

Here is a good article from the Azure CAT team that shows a couple of examples.

https://azure.microsoft.com/en-us/documentation/articles/best-practices-retry-service-specific/#service-bus-retry-guidelines

They suggest doing it like this:

namespaceManager.Settings.RetryPolicy = new RetryExponential(TimeSpan.FromSeconds(0.1),TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5), 3);
查看更多
登录 后发表回答