Spring Eureka: gently shutdown a service

浪尽此生 提交于 2019-12-21 05:47:08

问题


I have service A, that is using services B1 and B2 (two instances of same service), all configured via Eureka.

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:

  1. Tell B1 to stop pinging Eureka
  2. Make Eureka spread the word, that B1 is going down
  3. Wait until A gets the info and does not use B1 anymore
  4. Then shutdown B1

I have a problem with step 1. How can I request B1 to stop pinging? Looked for some JMX operation but not found.

(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)


回答1:


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>

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.




回答2:


According to this github question, you'd better add retry because DOWN instance would stay for some time before being removed, otherwise there could be failed client requests which are being routed to that instance.



来源:https://stackoverflow.com/questions/33231664/spring-eureka-gently-shutdown-a-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!