Spring Cloud learning five Eureka detailed analysis

 table of Contents

1. Infrastructure

2. Service governance mechanism

Three, analyze the source code

Four, configuration detailed analysis

5. Cross-platform support


1. Infrastructure

The Eureka service governance infrastructure consists of three core elements:

Service Registry: The server provided by Eureka, which provides the functions of service registration and service discovery.

Service provider: The application that provides the service can register the service provided by itself to eureka for other service areas to call.

Service consumer: The consumer application obtains the service list from the registry and finds the service it needs to call.

 

2. Service governance mechanism

(1) Service provider

              1. Service registration: When the service provider starts, it will register itself to EurekaServer through a REST request, and bring some metadata of the service itself. After EurekaServer receives the REST request, it stores the metadata in a two-layer Map. The first layer key is the service name, and the second layer key is the instance name of the specific service.

              2. Service synchronization: If two services are registered to two different registries, set the registries to register each other as services. When the service provider sends a request to one of the registries, it will be forwarded to the connected cluster Another registry, so that services can be synchronized.

              3. Service renewal: After the registration is completed, the service provider will maintain a heartbeat to continuously inform EurekaServer of its status to prevent EurekaServer from removing itself. This operation is called service renewal. Two important attributes of service renewal:

#定义服务续约任务的调用时间间隔
eureka.instance.lease-renewal-interval-in-seconds = 30
#服务失效时间
eureka.instance.lease-expireation-duration-in-seconds=90

 (2) Service consumers

               1. Get the service list: When the service consumer starts, it will initiate a rest request to the registry to get the service list (for performance reasons, the list is only readable). The cache list update time is 90 seconds by default, which can be set by eureka.client.registry-fetch-interval-seconds=30.

               2. Service call: Obtain metadata through the service name, and call which instance according to your needs. (Region and Zone concept)

               3. Service offline: If the service is normally closed, the registration center will be notified via rest request.

(3) Service Registration Center

              1. Invalidation removal: When EurekaServer starts, it will start a scheduled task by default. By default, services that are not renewed for more than (90 seconds) from the list will be removed by default every 60 seconds.

              2. Self-protection: fault-tolerant mechanism, circuit breaker, request retry, etc.

Three, analyze the source code

(To be added)

Four, configuration detailed analysis

(1) Service registration configuration: You can view the source code or official documents through org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean.

(2) Designation by the registration center: through eureka.client.service-url.defaultZon=http://localhost:1111/eureka/

The property sets the address of the registry. Multiple registries can be separated by commas. If you need security authentication, you can configure it at http://<username>:<password>@localhost:1111/eureka/, where username is the username and password is the password.

(3) Other configurations:

org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean Viewing the constants in this class can find that the default configuration can be found.

(4) Service instance configuration:

org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean Viewing the constants in this class can find that the default configuration can be found.

5. Cross-platform support

Eureka not only supports Java clients, but also other language platforms, such as eureka-js-client, python-eureka and so on.

Guess you like

Origin blog.csdn.net/weixin_42228950/article/details/102765881