How to build a highly available service registry by using Eureka cluster in SpringCloud
This article introduces how SpringCloud uses Eureka cluster to build a highly available service registry. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
In the actual development process, we may keep restarting the service. Because Eureka has its own protection mechanism, the service information will always exist in Eureka after the node goes offline. We can add some configurations to make the removal a little faster, of course, only in the development environment, not recommended in the production environment.
First, add two configurations to our eureka-server, which are to turn off the self-protection and cleanup intervals:
Eureka.server.enable-self-preservation=false# default 60000 millisecond eureka.server.eviction-interval-timer-in-ms=5000
Then configure the following in the specific client service:
Eureka.client.healthcheck.enabled=true# defaults to 30 seconds eureka.instance.lease-renewal-interval-in-seconds=5# defaults to 90 seconds eureka.instance.lease-expiration-duration-in-seconds=5
When eureka.client.healthcheck.enabled is used to turn on health check, you need to introduce the dependency of actuator into pom.xml, as shown below.
Org.springframework.bootspring-boot-starter-actuator
Where:
Eureka.instance.lease-renewal-interval-in-seconds represents the frequency at which the Eureka Client sends a heartbeat to the server side.
Eureka.instance.lease-expiration-duration-in-seconds indicates that the Eureka Server waits for the timeout of the next heartbeat after it received the last heartbeat from client, and removes the Instance if it does not receive the next heartbeat within this time.
For more Instance configuration information, please refer to the configuration class in the source code: org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean.
For more Server configuration information, please refer to the configuration class in the source code: org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean.
So much for sharing about how SpringCloud uses Eureka clusters to build a highly available service registry. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.