为ServiceBusTransientErrorDetectionStrategy实现指数重试策略

时间:2016-06-21 08:07:48

标签: azure error-handling azureservicebus servicebus azure-servicebus-topics

我正在尝试为Service Bus瞬态错误实施重试策略。我希望我的系统能够成倍地尝试像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))

这看起来不错吗?此政策是否会影响系统性能?

1 个答案:

答案 0 :(得分:1)

这是Azure CAT团队的一篇很好的文章,展示了几个例子。

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

他们建议这样做:

namespaceManager.Settings.RetryPolicy = new RetryExponential(TimeSpan.FromSeconds(0.1),TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5), 3);