【问题标题】:Rebus backoff and Polly supportRebus 退避和 Polly 支持
【发布时间】:2019-05-16 19:02:53
【问题描述】:

我对以下退避政策有疑问:

1 可以同时用于发布者(入队消息)和订阅者(​​出队消息)吗?

2 Rebus Backoff policy 和 Polly's Retry 一样吗?但是下面的描述提到了空闲时间,我有点困惑。

   //
    // Summary:
    //     Configures the timespans to wait when backing off polling the transport during
    //     idle times. backoffTimes must be a sequence of timespans, which indicates the
    //     time to wait for each second elapsed being idle. When the idle time exceeds the
    //     number of timespans, the last timespan will be used.
    public static void SetBackoffTimes(this OptionsConfigurer configurer, params TimeSpan[] backoffTimes);



Configure.With(...)
    .(...)
    .Options(o => {
        o.SetBackoffTimes(
            TimeSpan.FromMilliseconds(100),
            TimeSpan.FromMilliseconds(200),
            TimeSpan.FromSeconds(1)
        );
    })
            .Start();

3 Rebus 是否支持 Polly 扩展?例如,指数回退加上底部的一些抖动

Random jitterer = new Random(); 
Policy
  .Handle<HttpResponseException>() // etc
  .WaitAndRetry(5,    // exponential back-off plus some jitter
      retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))  
                    + TimeSpan.FromMilliseconds(jitterer.Next(0, 100)) 
  );

https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/implement-resilient-applications/implement-http-call-retries-exponential-backoff-polly

4 我在最新的 Rebus nutget 上找不到ISyncBackoffStrategy。是否已弃用?

 Configure.With(...)
        .(...)
        .Options(o => {
            o.Register<ISyncBackoffStrategy>(c => {
                var strategy = new MyOwnBackoffStrategy();
                return strategy;
            });
        })
        .Start();

https://github.com/rebus-org/Rebus/wiki/Back-off-strategy

【问题讨论】:

    标签: rebus rebus-azureservicebus


    【解决方案1】:

    Rebus 的退避策略仅由消息消费者使用,因此可以在工作较少的情况下放松。

    这与 RETRY 无关,更多的是在安静的时候轻松使用 CPU。

    文档中的术语“空闲时间”仅表示“没有收到消息的时间”。所以,只要队列中有消息,Rebus 会以你能处理的最快速度处理消息,但如果队列突然空了,那么它会逐渐轮询越来越少。

    您可以通过实现IBackoffStrategy 来实现自己的退避策略(现在就是这样,我已经相应地更新了 wiki)。

    【讨论】:

    • 谢谢。正如您所提到的,IBackoffStrategy 更多的是关于空闲时间。这与我心中的“退避”策略不同,如问题3所示。它是指在处理过程中出现错误时,退避开始。在这种情况下,Rebus的解决方案是什么? Polly 擅长这种场景,Rebus 是否支持?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多