SpringBoot 禁用 rabbitTemplate 用于兔子健康检查的重试策略 [英] SpringBoot Disable rabbitTemplate retry policy for rabbit health check
问题描述
我的 SpringBoot 配置包含非常强大的 rabbitTemplate 重试策略
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
这个配置的问题是当健康端点被调用并且rabbitMQ关闭时,连接挂起真的很长时间.
The problem with this configuration is when health endpoint is called and rabbitMQ is down, the connections hangs for really long time.
添加像
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
没有帮助,因为retry.multiplier=5
,所以无论如何都会花费很多时间.
does not help, since the retry.multiplier=5
, so it will take a lot of time anyway.
如果我们不考虑重试策略是否好,有没有办法禁用rabbitTemplate 对健康检查端点的重试或至少给它一些超时时间?
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?
推荐答案
您可以覆盖默认的健康指示器 bean 以使用模板而不启用重试...
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));
}
}
这篇关于SpringBoot 禁用 rabbitTemplate 用于兔子健康检查的重试策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!