spring 云流兔子的退避设置

Backoff settings for spring cloud stream rabbit

我仍在使用 rabbitmq 和 spring 云消息传递设置示例消息传递系统,但遇到错误 (?),或者我误解了文档。 (使用 spring-引导版本 2.0.3.RELEASE)

为了这个例子,我想要以下设置

  spring:
    cloud:
      stream:
        rabbit:
          bindings:
            foo:
              consumer:
                auto-bind-dlq: true
        instanceCount: 2
        instanceIndex: 0
        bindings:
          foo:
            destination: foo
            group: fooGroup
            consumer:
              maxAttempts: 4
              backOffInitialInterval: 10000
              backOffMultiplier: 10.0 
          fooChannel:
            destination: foo

这个问题的有趣部分是 spring.cloud.stream.bindings.foo.consumer 部分,我在其中设置了 4 个 maxAttempts,初始退避间隔为 10 秒,乘数为 10。

应用了 maxAttempts 和初始间隔,但没有应用乘数。根据文档 (here and here),键是驼峰式的,但是 backOffInitialInterval 似乎在像 back-off-initial-interval 一样应用时也能正常工作。我对键的所有不同封装方式感到有点困惑,但那是另一回事了。

我已经尝试了所有可能的写法backOffMultiplier,但它没有被应用,消息每 10 秒发送一次。

现在,为了测试真正的问题所在,我设置了 @Bean 并手动配置了 RetryTemplate

@Bean
    RetryTemplate retryTemplate() {
        RetryTemplate r = new RetryTemplate();

        ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy();
        exponentialBackOffPolicy.setInitialInterval(10000);
        exponentialBackOffPolicy.setMultiplier(10.0);
        exponentialBackOffPolicy.setMaxInterval(100000);
        r.setBackOffPolicy(exponentialBackOffPolicy);

        SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy();
        simpleRetryPolicy.setMaxAttempts(4);
        r.setRetryPolicy(simpleRetryPolicy);
        return r;

    }

使用这个 bean,一切都得到正确应用,所有设置都得到遵守。

是我在application.yml中设置配置道具不正确,还是哪里出了问题?

spring-retry ExponentialBackOfPolicy 有计算间隔的上限,由 maxInterval 定义。

Spring Cloud Stream 将其公开为 属性 backOffMaxInterval.

巧合的是,默认是10秒。

您也需要设置 属性。我看到你在 @Bean 版本中这样做。

I'm a bit confused by all the different ways the keys are cased, but that's another story.

Java *Properties 类 上的 属性 名称当然是驼峰式。

属性 名称的转换,例如back-off-max-intervalbackOffMaxInterval 是 Spring 启动功能。