简体   繁体   中英

Backoff settings for spring cloud stream rabbit

I'm still setting up an example messaging system using rabbitmq and spring cloud messaging and am encountering a bug (?), or I'm misunderstanding the documentation. (Used spring-boot version 2.0.3.RELEASE)

For the sake of this example, I want the following settings

  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

The interesting part of this question is spring.cloud.stream.bindings.foo.consumer part, where I've set 4 maxAttempts, an initial backoff Interval of 10s and a multiplier of 10.

The maxAttempts and the initial Interval are applied, but the multiplier isn't. According to the docs ( here and here ) the keys are camel cased, however backOffInitialInterval seems to be working when applied like back-off-initial-interval too. I'm a bit confused by all the different ways the keys are cased, but that's another story.

I've tried every possible kind of writing backOffMultiplier , but it does not get applied, the message gets sent every 10s.

Now, to test what's really wrong, I've setup a @Bean and configured the RetryTemplate manually

@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;

    }

Using the bean, everything gets applied correctly and all the settings are respected.

Is it me who's setting the configuration props in application.yml incorrectly, or where's the issue coming from?

The spring-retry ExponentialBackOfPolicy has a cap for the computed interval, defined by maxInterval .

Spring Cloud Stream exposes this as property backOffMaxInterval .

Coincidentally, the default is 10 seconds.

You need to set that property too. I see you are doing so in your @Bean version.

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

The property names on the Java *Properties classes are, of course, camelCased.

The conversion of property names from, eg back-off-max-interval to backOffMaxInterval is a Spring Boot feature.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM