Overview: Eureka is a major component in SpringCloud's family bucket for service registration and discovery. The company recently studied Eureka cluster deployment in order to restructure the microservices architecture.

Eureka is an open source service registration and discovery component of Netflix. The server exposes the service through REST protocol and provides the registration and discovery functions of application services.

All Eureka services are called instances. Eureka includes Eureka Server and Eureka Client

EurekaClient is divided into Service providers and Service consumers. Each client can be regarded as an instance Service Provider: Service Consumer: A Service Consumer obtains a list of services from eureka-Server, either full or incremental.

When the Eureka Server receives the heartbeat, it updates the information about the corresponding service instance. If the information about the instance changes, the Eureka Server adds the instance to the queue of the latest changed instance. The service consumer creates a timer to update the service instance, first pulling the service instance in full, followed by an incremental pull, that is, pulling the change instance information from the change queue.

Eureka Server is deployed in a cluster

In production environments where single-node servers may not be suitable due to external or network factors, supporting cluster deployment reflects Eureka’s high availability.

Multiple Eureka servers are registered with each other to form a cluster, and each Eureka Server is registered with other servers as a service provider through eureka.client.service-url.defaultzone configuration.

Eureka configuration

  • Eureka. Instance.*: Indicates the configuration of eureka instances. This configuration item is common for both eureka servers and clients. The corresponding configuration class for org.springframework.cloud.net flix. Eureka. EurekaInstanceConfigBean.

  • Eureka. Server.*: Indicates the option of eureka server configuration. This option is required only when Eureka is used as the registry. The corresponding configuration class for org.springframework.cloud.net flix. Eureka. EurekaServerConfigBean.

  • Eureka. Client.*: Options configured by the Eureka Client, that is, when the service needs to be registered with or use a service in the registry. The corresponding configuration class for org.springframework.cloud.net flix. Eureka. Server EurekaClientConfigBean

    Eureka Client

    Eureka Client is divided into two roles: service provider and service consumer. To register Eureka on the Client, you need to configure the cluster address on Eureka.client.service-url.defaultzone. In fact, you can also configure Eureka Server. Because of the service synchronization mechanism of Eureka Server.

Eureka Server service synchronization

When each Eureka service changes, the services are synchronized regularly. In the intermediate process, each service may be inconsistent, and ultimately the consistency of the service will be guaranteed.Copy the code

To ensure that the status of all Eureka Server nodes in the cluster is synchronized, all the following operations are synchronized to all services in the cluster: Registers, Renewals, Cancels, Expirations and Status Changes. The concrete is com.net flix. Eureka. Registry. PeerAwareInstanceRegistryImpl

Service registration: Copy to all other nodes after registration

Service cancellation:

Eureka Server protection mechanism:

The Eureka Server self-protection mechanism means that if the number of heartbeat beats received by the Eureka Server per minute is less than the actual number due to network reasons, the Eureka Server triggers the protection mechanism and all services are not removed offline.Copy the code

Here is an explanation of how to calculate the number of heartbeats that should be received:

If there are 3 instances registered on eureka server, then under normal circumstances Renews (last min) means the number of heartbeats received per minute is 6, the expected number of heartbeats received is 6*0.85=5.1, and the expected number of heartbeats received is 5 (if it is not an integer, it is the tail method). If the number of received heartbeats in the last minute is less than the expected number, the protection mechanism is enabled.Copy the code