我仍在使用rabbitmq和spring云消息传递设置示例消息传递系统,但遇到了错误(?),或者我误解了文档。 (使用spring-boot版本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 https://docs.spring.io/spring-cloud-stream/docs/Elmhurst.RELEASE/reference/htmlsingle/#spring-cloud-stream-overview-error-handling and here https://docs.spring.io/spring-cloud-stream/docs/Brooklyn.RELEASE/reference/html/_configuration_options.html)但是钥匙是驼峰式的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 中错误地设置了配置属性,还是问题出在哪里?