In the actual development process , We might be able to restart the service all the time , because Eureka It has its own protection mechanism , Therefore, after the node is offline , Service information will always exist in Eureka in . We can make the removal faster by adding some configurations , Only in the development environment, of course , It is not recommended in production environment .
First of all in our eureka-server Two new configurations are added in , Turn off self-protection and clean-up interval ：
eureka.server.enable-self-preservation=false # Default 60000 millisecond eureka.server.eviction-interval-timer-in-ms=5000
Then configure the following content in the specific client service ：
eureka.client.healthcheck.enabled=true # Default 30 second eureka.instance.lease-renewal-interval-in-seconds=5 # Default 90 second eureka.instance.lease-expiration-duration-in-seconds=5
eureka.client.healthcheck.enabled It's used to turn on the health check , Need to be in pom.xml Introduction in actuator Dependence , The code is as follows .
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
- eureka.instance.lease-renewal-interval-in-seconds Express Eureka Client Send a heartbeat to server The frequency of the end .
- eureka.instance.lease-expiration-duration-in-seconds Express Eureka Server Last received client After my heart beat , Timeout waiting for next heartbeat , If you don't receive the next heartbeat in this time , Then remove the Instance.
added Instance For configuration information, please refer to the configuration class in the source code ：org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean.
added Server For configuration information, please refer to the configuration class in the source code ：org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean.