SpringBoot Disable rabbitTemplate retry policy for rabbit health check

你。 提交于 2020-01-01 19:37:33

问题


My SpringBoot configuration contains very strong retry policy for rabbitTemplate retries

spring:
  rabbitmq:
    template:
      retry:
        enabled: true
        initial-interval: 500
        max-attempts: 10
        multiplier: 5
        max-interval: 60000

The problem with this configuration is when health endpoint is called and rabbitMQ is down, the connections hangs for really long time.

Adding properties like

spring.rabbitmq.connection-timeout=500 or
spring.rabbitmq.template.receive-timeout=500 or
spring.rabbitmq.template.reply-timeout=500 or 
spring.rabbitmq.requested-heartbeat=1

does not help, since the retry.multiplier=5, so it will take a lot of time anyway.

If we disregard whether the retry policy is good or not, is there a way to disable rabbitTemplate retries for health check endpoint or at least give it some timeout?


回答1:


You can override the default health indicator bean to use a template without retry enabled...

@Configuration
public class MyRabbitHealthIndicatorOverride
        extends CompositeHealthIndicatorConfiguration<RabbitHealthIndicator, RabbitTemplate> {

    @Bean
    public HealthIndicator rabbitHealthIndicator(ConnectionFactory connectionFactory) {
        return createHealthIndicator(new RabbitTemplate(connectionFactory));
    }

}


来源:https://stackoverflow.com/questions/42362393/springboot-disable-rabbittemplate-retry-policy-for-rabbit-health-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!