问题
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:
- Tell B1 to stop pinging Eureka
- Make Eureka spread the word, that B1 is going down
- Wait until A gets the info and does not use B1 anymore
- 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