consul健康检测
·
consul健康检查一般有两种方式:
1.手动加一个GET方法的健康检测API
@RestController
public class HealthApi {
@GetMapping("/health")
public String health(){
return "hello consul";
}
}
然后在配置文件中加上spring.cloud.consul.discovery.health-check-path的路径
spring:
cloud:
consul:
host: localhost
port: 8500
discovery:
health-check-path: /health
application:
name: springcloud-consul
server:
port: 9999
Consul用于检查运行状况端点的间隔默认是10s,每过10秒检测一次
2.加入actuator依赖(推荐使用)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
不需要改spring.cloud.consul.discovery.health-check-path,
默认的就行,默认是/actuator/health。

通过健康检测可以看到服务状态是UP,服务已经注册到Consul上
更多推荐



所有评论(0)