Spring Eureka:轻轻关闭服务 [英] Spring Eureka: gently shutdown a service
问题描述
我有服务A,它使用服务B1和B2(同一服务的两个实例),所有服务都通过Eureka配置.
I have service A, that is using services B1 and B2 (two instances of same service), all configured via Eureka.
现在,我要轻轻地取下B1(这样A不会遇到处理失败的B1请求的问题/延迟).我想要一个这样的程序:
Now I would like to take B1 gently down (so that A has not problems/delays with handling failing B1 requests). I would like to have such a procedure for that:
- 告诉B1停止对Eureka进行ping
- 让尤里卡(Eureka)宣告说B1正在下降
- 等待直到A获得信息并且不再使用B1
- 然后关闭B1
我在第1步中遇到问题.如何请求B1停止查验?寻找了一些JMX操作,但没有找到.
I have a problem with step 1. How can I request B1 to stop pinging? Looked for some JMX operation but not found.
(如果我跳过了第1步,只是从Eureka中删除了B1,它将被从注册表中删除,但是由于B1仍然对Eureka执行ping操作,因此它会快速更新)
(If I skipped step 1, and just DELETE B1 from Eureka, it is removed from registry, but it will be quickly renewed, because B1 is still pinging Eureka)
推荐答案
如果将cloud-starter
和actuator
依赖项添加到项目中
If you add the cloud-starter
and actuator
depencency to your project
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
您将有许多管理端点(由actuator
提供). POST
到/pause
将导致尤里卡中的DOWN
状态(感谢cloud-starter
).当eureka客户端收到状态时,Ribbon将不会将任何请求路由到您的DOWN
服务.发布到/shutdown
将正常停止该应用程序.
you will have a number of managing endpoints (provided by actuator
). A POST
to /pause
will result in a status of DOWN
in eureka (thanks to cloud-starter
). When the eureka clients receive the status, Ribbon won't route any request to your DOWN
service. Posting to /shutdown
will gracefully stop the application.
这篇关于Spring Eureka:轻轻关闭服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!