当前位置: 首页 > 知识库问答 >
问题:

带领事的Spring引导执行器

汪正雅
2023-03-14

在Consul,可以查看SpringBoot应用程序中配置的健康状态。

或者我们是否可以让Consult拉出/调用某个服务的任何服务/URL,以便在Consult中查看响应?

共有1个答案

方昊
2023-03-14

Consul正在使用健康终结点来确定服务实例是否健康。如果您想要自定义健康状态(考虑一些自定义度量),那么您应该实现HealthIndicator接口。

通过在Application.Properties中设置Management.Security.Enabled=False,可以在health api中公开更多信息

在这种情况下,您将在Consuld admin UI中看到类似于您的服务的内容

HTTP GET http://192.168.0.102:8080/health: 200  Output: {"description":"Composite Discovery Client","status":"UP","discoveryComposite":{"description":"Composite Discovery Client","status":"UP","discoveryClient":{"description":"Composite Discovery Client","status":"UP","services":["application","consul"]}},"diskSpace":{"status":"UP","total":499963170816,"free":341478899712,"threshold":10485760},"consul":{"status":"UP","leader":"127.0.0.1:8300","services":{"application":[],"consul":[]}},"hystrix":{"status":"UP"}}

您可以将健康URL配置到不同的endpoint。例如,如果您指定spring.cloud.convers.discovery.HealthCheckPath=/health2,那么您的spring-boot实例将注册到以下json(请参阅下面的日志片段):

Registering service with consul: NewService{id='application', name='application', tags=[], address='192.168.0.102', port=8080, enableTagOverride=null, check=Check{script='null', interval='10s', ttl='null', http='http://192.168.0.102:8080/health2', tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null}
 类似资料: