【问题标题】:Disabling customer health check - Hystrix禁用客户健康检查 - Hystrix
【发布时间】:2018-02-27 11:37:03
【问题描述】:

有没有办法禁用下面列出的 hystrix 自定义健康检查 -

@Component
@ConditionalOnClass(name = "org.springframework.cloud.netflix.hystrix.HystrixHealthIndicator")
public class XspHystrixHealthIndicator extends AbstractHealthIndicator {

当我检查 localhost:8080/health 时,我看到以下内容

{
"status": "UP",
"xspHystrix": {
"status": "UP"
},
"manualSwitch": {
"status": "UP"
},
"redis": {
"status": "UP",
"version": "3.0.7"
},
"hystrix": {
"status": "UP"
}
}

我不希望列出 xspHystrix 和 hystrix,它们不应该成为健康检查的一部分。

我添加了以下属性并且不再看到 hystrix,但我仍然看到我不想显示的 xspHystrix -

management:
  health:
    hystrix:
      enabled: false
    xspHystrix:
      enabled: false

【问题讨论】:

  • 你应该使用health.config.enabled=false
  • 我只想禁用上面列出的 hystrix。有办法吗?

标签: java spring-boot


【解决方案1】:

不,如果不更改XspHystrixHealthIndicator.java 的代码,您将无法做到这一点。

Spring Boot 健康执行器 聚合所有实现 HealthIndicator 的 Spring bean。如果您将XspHystrixHealthIndicator 放在组件扫描路径中,它将被聚合到 Health actuator 中。

如果您可以更改XspHystrixHealthIndicator.java,请尝试以下操作。 首先,从XspHystrixHealthIndicator 中删除@Component@ConditionalOnClass。然后创建您自己的配置类,它将根据属性加载您的XspHystrixHealthIndicator bean。它可能看起来像下面的东西。

@Configuration
@ConditionalOnClass(name = "org.springframework.cloud.netflix.hystrix.HystrixHealthIndicator")
public class XpsHystrixAutoConfiguration {   
    @Bean
    @ConditionalOnEnabledHealthIndicator("xspHystrix")
    public XspHystrixHealthIndicator xpsHystrixHealthIndicator() {
        return new XspHystrixHealthIndicator();
    }  
}

【讨论】:

猜你喜欢
  • 2019-02-23
  • 2020-11-16
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 2019-08-28
  • 2014-10-02
  • 2021-09-13
  • 2019-11-03
相关资源
最近更新 更多