【问题标题】:Configure consul health check to spring boot actuator '/health'将 consul 健康检查配置为 spring boot actuator '/health'
【发布时间】:2019-08-05 03:56:13
【问题描述】:

对于我一直在研究的微服务,我创建了一个自定义健康检查类,扩展了 AbstractHealthIndicator 并能够获取输出

http://localhost:8080/actuator/health

但是当我向 consul 注册服务时,健康检查状态是失败的。

尝试在引导程序中使用 consul 健康检查将执行器 url 配置为spring.cloud.consul.discovery.health-check-url= http://localhost:8080/actuator/health。但它仍然失败并出现错误Get http://localhost:8566/actuator/health: dial tcp 127.0.0.1:8566: connect: connection refused

如果我尝试使用health-check-path: /actuator/health,它根本不会走这条路,默认为http://QINDW062.it.local:8566/my-health-check

有什么建议吗?

编辑:

【问题讨论】:

  • 您的领事客户端是否与您的应用程序在同一台机器上运行?你能提供你的服务定义(consul.io/docs/agent/services.html#service-definition)吗?
  • consul 正在通过 docker 运行。在引导程序中配置了 ip,我的应用程序能够从中读取值。

标签: spring spring-boot microservices consul spring-boot-actuator


【解决方案1】:

您需要在配置文件(例如 application.yml)中设置一个指向您的健康检查端点的属性:

spring:
  cloud:
    consul:
      discovery:
        healthCheckPath: /actuator/health

您还可以使用以下属性决定健康检查的时间间隔(Consul 多久调用一次健康检查):

spring:
  cloud:
    consul:
      discovery:
        healthCheckInterval: 20s

【讨论】:

    猜你喜欢
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多