diff --git "a/docs/java/framework/springcloud\344\274\230\351\233\205\344\270\213\347\272\277\346\234\215\345\212\241.md" "b/docs/java/framework/springcloud\344\274\230\351\233\205\344\270\213\347\272\277\346\234\215\345\212\241.md" index 383a2786..ecd7a86e 100644 --- "a/docs/java/framework/springcloud\344\274\230\351\233\205\344\270\213\347\272\277\346\234\215\345\212\241.md" +++ "b/docs/java/framework/springcloud\344\274\230\351\233\205\344\270\213\347\272\277\346\234\215\345\212\241.md" @@ -1,71 +1,68 @@ # springcloud优雅下线服务 - - ## 问题场景 线上问题需要紧急修复部署,但是服务一直在跑,网关还会一直往服务中路由请求进行处理,如果直接停掉服务,客户端会出现业务中断的问题。因此需要在替换更新前先手动下线服务,这样用户请求不会被分发到下线的节点上,就可以直接进行更新而不影响用户体验。 - - ## 实现 ### 查询注册中心中服务的状态 ```bash -curl -GET -u eureka_username:eureka_password http://eureka_ip:eureka_port/eureka/apps/服务名称/实例ip:实例名称:实例port +curl -X GET -u eureka_username:eureka_password http://eureka_ip:eureka_port/eureka/apps/服务名称/实例ip:实例名称:实例port ``` 例如 ```bash -curl -GET -u admin:admin123 http://127.0.0.1:19991/eureka/apps/app-platform/127.0.0.1:app-platform-1.0.0-SNAPSHOT:8001 +curl -X GET -u admin:admin123 http://127.0.0.1:19991/eureka/apps/app-platform/127.0.0.1:app-platform-1.0.0-SNAPSHOT:8001 ``` #### 结果 ```xml + - 127.0.0.1:app-platform-2.0.0-SNAPSHOT:8001 - 127.0.0.1 - app-platform - 127.0.0.1 - UP # 状态为在线 - UNKNOWN # 重写状态为空 - 8001 - 443 - 1 - - MyOwn - - - 10 - 30 - 1636639654493 - 1636961178498 - 0 - 1636639654493 - - - 8001 - 127.0.0.1_kkg - - http://127.0.0.1:8001/ - http://127.0.0.1:8001/actuator/info - http://127.0.0.1:8001/actuator/health - app-platform - app-platform - false - 1636639654493 - 1636639654480 - ADDED + 127.0.0.1:app-platform-2.0.0-SNAPSHOT:8001 + 127.0.0.1 + app-platform + 127.0.0.1 + UP + # 状态为在线 + UNKNOWN + # 重写状态为空 + 8001 + 443 + 1 + + MyOwn + + + 10 + 30 + 1636639654493 + 1636961178498 + 0 + 1636639654493 + + + 8001 + 127.0.0.1_kkg + + http://127.0.0.1:8001/ + http://127.0.0.1:8001/actuator/info + http://127.0.0.1:8001/actuator/health + app-platform + app-platform + false + 1636639654493 + 1636639654480 + ADDED ``` ### 通知注册中心服务下线 - - ```bash curl -i -X PUT -u eureka_username:eureka_password http://eureka_ip:eureka_port/eureka/apps/服务名称/实例ip:实例名称:实例port/status?value=OUT_OF_SERVICE ``` @@ -94,47 +91,48 @@ Date: Mon, 15 Nov 2021 07:30:32 GMT #### 再次查询服务状态 ```xml + - 127.0.0.1:app-platform-2.0.0-SNAPSHOT:8001 - 127.0.0.1 - app-platform - 127.0.0.1 - OUT_OF_SERVICE # 服务状态-已下线 - OUT_OF_SERVICE # 重写状态为已下线 - 8001 - 443 - 1 - - MyOwn - - - 10 - 30 - 1636639654493 - 1636961468691 - 0 - 1636639654493 - - - 8001 - 127.0.0.1_kkg - - http://127.0.0.1:8001/ - http://127.0.0.1:8001/actuator/info - http://127.0.0.1:8001/actuator/health - app-platform - app-platform - false - 1636961432181 - 1636639654480 - MODIFIED + 127.0.0.1:app-platform-2.0.0-SNAPSHOT:8001 + 127.0.0.1 + app-platform + 127.0.0.1 + OUT_OF_SERVICE + # 服务状态-已下线 + OUT_OF_SERVICE + # 重写状态为已下线 + 8001 + 443 + 1 + + MyOwn + + + 10 + 30 + 1636639654493 + 1636961468691 + 0 + 1636639654493 + + + 8001 + 127.0.0.1_kkg + + http://127.0.0.1:8001/ + http://127.0.0.1:8001/actuator/info + http://127.0.0.1:8001/actuator/health + app-platform + app-platform + false + 1636961432181 + 1636639654480 + MODIFIED ``` 可以看到此时,服务状态为已经下线,不过还是要等到网关服务不再路由请求到该服务时再停掉服务。 - - ### 通知注册中心服务上线 ```bash @@ -147,8 +145,6 @@ curl -i -X DELETE -u eureka_username:eureka_password http://eureka_ip:eureka_por curl -i -X DELETE -u admin:admin123 http://127.0.0.1:19991/eureka/apps/app-platform/127.0.0.1:app-platform-1.0.0-SNAPSHOT:8001/status ``` - - #### 结果 ```bash @@ -167,40 +163,42 @@ Date: Mon, 15 Nov 2021 07:37:11 GMT #### 再次查询服务状态 ```xml + - 127.0.0.1:app-platform-2.0.0-SNAPSHOT:8001 - 127.0.0.1 - app-platform - 127.0.0.1 - UP # 此时服务已上线 如果通知后立刻查询,状态可能会是unknown,隔一段时间再查询即可 - UNKNOWN - 8001 - 443 - 1 - - MyOwn - - - 10 - 30 - 1636961828894 - 1636961861799 - 0 - 1636639654493 - - - 8001 - 127.0.0.1_kkg - - http://127.0.0.1:8001/ - http://127.0.0.1:8001/actuator/info - http://127.0.0.1:8001/actuator/health - app-platform - app-platform - false - 1636961828894 - 1636961828889 - ADDED + 127.0.0.1:app-platform-2.0.0-SNAPSHOT:8001 + 127.0.0.1 + app-platform + 127.0.0.1 + UP + # 此时服务已上线 如果通知后立刻查询,状态可能会是unknown,隔一段时间再查询即可 + UNKNOWN + 8001 + 443 + 1 + + MyOwn + + + 10 + 30 + 1636961828894 + 1636961861799 + 0 + 1636639654493 + + + 8001 + 127.0.0.1_kkg + + http://127.0.0.1:8001/ + http://127.0.0.1:8001/actuator/info + http://127.0.0.1:8001/actuator/health + app-platform + app-platform + false + 1636961828894 + 1636961828889 + ADDED ```