前言
我们利用远程关闭功能可以实现优雅地关闭指定地服务。
正文
本文依然使用v1.5.8.RELEASE ,讲地是利用actuator的Endpoints实现关闭服务
首先准备一个eureka服务,然后启动他。
然后准备一个eureka客户端服务,客户端的pom除了必要的springboot的web依赖还需要添加依赖如下
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在eureka客户端服务的application.properties文件开启shutdown endpoint,SpringBoot的endpoints.shutdown.enabled默认是关闭的。
eureka.client.service-url.defaultZone=http://admin:admin@localhost:1111/eureka/
server.port=8762
spring.application.name=eureka-client
#启用shutdown
endpoints.shutdown.enabled=true
#禁用密码验证
endpoints.shutdown.sensitive=false
#如果用的2.x版本的 就用注释的那四行配置
#management.endpoints.shutdown.enabled=true
#management.endpoints.health.enabled=true
#management.endpoints.web.base-path=/
#management.en