根据Spring Cloud Consul manual的第3.2节:
默认情况下会创建一个HTTP检查,Consul会命中/ health 终点每10秒。
但是,我的应用程序日志显示缺少此运行状况检查。属性http应该有一个有效的URL,间隔应该有10秒,两者都是null:
与领事注册服务: 新服务{id =' test-service-local-8081',name =' test-service',tags = [], address =' localhost',port = 8081,enableTagOverride = null, check =检查{script =' null',interval =' null',ttl =' 30s',http =' null', tcp =' null',timeout =' null',deregisterCriticalServiceAfter =' null', tlsSkipVerify = null,status =' null'},checks = null}
此外,当我使我的健康状况终点返回"状态:向下"时,领事仍然报告我的服务没问题。
如何在使用Consul注册Spring Boot服务时将HTTP检查添加到/ health?
我使用以下属性:
management:
endpoints:
web:
base-path: /manage
spring:
application:
name: test-service
cloud:
consul:
host: consul
port: 8500
discovery:
healthCheckInterval: 10s
healthCheckPath: "${management.endpoints.web.base-path}/health"
heartbeat:
enabled: true
hostname: localhost
编辑:事实证明,heartbeat.enabled = true属性会删除默认的HTTP检查。删除此属性时,我们可以在日志中看到HTTP检查:
与领事注册服务: 新服务{id =' test-service-local-8081',name =' test-service', tags = [],address =' erwins-mbp.home',port = 8081,enableTagOverride = null, check =检查{script =' null',interval =' 1s',ttl =' null', http =' http://mbp.home:8081/manage/health',tcp =' null', timeout =' null',deregisterCriticalServiceAfter =' null', tlsSkipVerify = null,status =' null'},checks = null}
那么,现在问题是,在启用心跳的情况下,如何将Spring Boot的HTTP检查注册到Consul?