如果直接KILL SpringCloud的服务,因为Eureka采用心跳的机制来上下线服务,会导致服务消费者调用此已经kill的服务提供者然后出错,处理这种情况有2中方案。

一、利用Spring Boot Actuato的管理端点(推荐

1、pom中引用Actuato

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2、properties中添加如下内容

#启用shutdown
endpoints.shutdown.enabled=true
#禁用密码验证
endpoints.shutdown.sensitive=false

如果只允许本机访问,可以添加如下属性

#(只允许本机访问)
server.address=localhost

3、在服务器上利用curl发送shutdown命令

curl -X POST http://localhost:8080/shutdown

或者

curl -d "" http://localhost:8080/shutdown

 

二、利用Eureka的rest管理端点下线服务

eureka界面注册的服务:

 

 发送DELETE的Restfull请求

对照关系看上面的2张图。

 注意:由于cloud服务是心跳检测,所有在eureka进行DELETE后要快速的停止服务,否则服务可能会被重新注册上。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐