spring-cloud 服务优雅下线

  在集群环境下,zuul后面的api服务一般会有多个实例,当下线某个实例时,如果使用 kill -9 pid 的方式,会造成这个服务在eureka中还存在,请求还会路由到这个服务上面,造成500,所以需要先将服务在eureka中下线之后再kill

我默认你已经使用了eureka

1.首先需要在pom.xml中添加actuator

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

2.修改application.yml文件,添加:

endpoints.shutdown.enabled: true    #开启优雅关闭方式

3.下线服务

curl -X POST "http://{ip}:{port}/{context}/shutdown"

如果成功,会有以下响应:
{
    “message”:"Shutting down, bye..."
}
原文地址:https://www.cnblogs.com/ncbest/p/8118600.html