Spring Cloud core components Detailed

A, Spring Cloud core components: Eureka

(1)Netflix Eureka

1), Eureka server: also known as the service registry, like other service registry, to support high-availability configurations. If Eureka deployed in cluster mode, when the film took part in the cluster fails, then transferred to Eureka on self-protection mode. It allows to continue to provide service discovery and registration of fragmentation during a fault, when the fault slices recovery operation, a cluster of other fragments will synchronize their state back again

2), Eureka client: The main registration process and discovery services. The client service arranged by annotations and parameters, embedded in the code of the client application, the application is running, the client would like to register the Eureka central registration service provided by itself and periodically sends a heartbeat to update its service lease . It also query the service information from the server currently registered and put them to the local cache and periodically refresh the service status

3), high availability Eureka Server is actually registers itself as a service to other registry yourself, so that you can form a group of service registry registration with each other to achieve a list of services synchronized with each other, to achieve high availability effect

(2) Eureka Comments

1), service providers

A. Registration Service

Service providers will be at startup to register themselves by sending the Eureka Server REST requests, as well as bring some metadata information own services. After REST Eureka Server receives this request, the metadata information is stored in a two-layer structure in the Map, key wherein the first layer is a service name, key of the second layer is a specific instance name service

B. Synchronization Service

Two service providers were registered to two different service registry, that is, their information are maintained by two service registry. At this time, since the registration between a service registry with each other as a result of the service, when the service provider sends a registration request to register a service center, which forwards the request to the other register connected to the center of the cluster in order to achieve registration between the center the synchronization service. , Two service providers can obtain service information to the service by these two synchronized via service registry Renyiyitai

C. Service Renewal

After completion of registration services, the service provider will maintain a continuous heartbeat to tell Eureka Server: "I'm alive" to prevent culling task Eureka Server service instances of exclusion from the list of services to go out, we call this operation as a service renewal

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

2), consumer services

A. Access Service

When we start the service consumer, it sends a request to the REST service registry, to obtain a list of services registered above. For performance reasons, Eureka Server maintains a read-only list of service back to the client, while the cache list will be updated once every 30 seconds

# 缓存清单的更新时间,默认30秒
eureka.client.registry-fetch-interval-seconds=30

B. Service Call

Metadata information service consumers after getting the list of services, you can get the specific services provided by the service name and the instance name of the instance. In the Ribbon will default polling of call, in order to achieve load balancing client

For instance choose to access, and the Eureka Zone Region in the concept of a plurality of Zone Region may comprise, for each service needs to be registered to the client in a Zone, each corresponding to a client and a Zone Region. When making a service call, priority access to the same at a service provider in the Zone, if not visit, you visit other Zone

C. Service offline

When a service instance for normal operation shut down, it will trigger a request to the REST service offline Eureka Server, told the service registry: "I want off the assembly line." After the server receives the request, the service status to offline (DOWN), and to spread out the offline event

3), the service registry

A. Failure rejected

When Eureka Server creates a scheduled task at boot time, the default (default is 60 seconds) of the current Super League list from time to time (the default is 90 seconds) did not renew removed out of service

B. Self-protection

A red warning message in the information panel service registration center:

The warning is triggered a self-protection mechanism of Eureka Server. Eureka Server during operation, will be counted whether the proportion of heart failure less than 85% within 15 minutes, if the situation appears less than, Eureka Server instance current registration information will be protected, so that these instances do not expire and do You may protect the registration information. However, in instances when problems arise during this protection, then the client can easily get the actual service instance that no longer exists, calling the situation a failure of will, so the client must have a fault-tolerant mechanisms such request can be used to retry mechanism, circuit breakers, etc.

# 关闭保护机制,以确保注册中心可以将不用的实例正确剔除(本地调试可以使用,线上不推荐)
eureka.server.enable-self-preservation=false

Two, Spring Cloud core components: Ribbon

Ribbon is based on HTTP and TCP client load balancer, which can be configured by the client ribbonServerList server list to polling access services in order to achieve a balanced role. When used in conjunction with Eureka and Ribbon, Ribbon list of examples of RibbonServerList service will be DiscoveryEnabledNIWSServerList rewritten, expanded to obtain the server list from Eureka registry. At the same time it will be replaced with NIWSDiscoveryPing IPing, it will delegate responsibilities to Eureka come and whether the server has started

Client load balancing, all client node maintains its own list of the server to be accessed, and the list of such services from the end of the service registry (such as Eureka). Client load balancing is also required to maintain heart health of the server list, but this step needs to work with complete service registry

By Spring Cloud Ribbon package, we use client load balancing call micro-services architecture requires only two steps as follows:

  • Service providers just need to start multiple service instances registered with the service registry and a registry or more associated
  • Service consumers directly @LoadBalanced comment by calling the RestTemplate been modified to achieve a service-oriented interface calls

Three, Spring Cloud core components: Fegin

Fegin key mechanism is the use of dynamic proxies

1) First, for an interface defines @FeginClient notes, Fegin will be a proxy for this interface to create dynamic

2), and then call the interface when the call is essentially created dynamic proxy Fegin

3), Fegin dynamic proxy @RequestMapping the like based on the annotation interface dynamically configured to address the service request

4) for this address initiates a request, parse the response

Fegin and Ribbon and Eureka is close collaboration

1) First Ribbon will get from Eureka Client in the corresponding service registry, will know all the services which are deployed on the machine, listening on which ports

2), then you can use the default Ribbon Round Robin algorithm, choose a machine

3), Fegin will for this machine, constructed and initiated the request

Four, Spring Cloud core components: Hystrix

In the micro-service architecture, there are so many services unit, if one unit fails, it is easy to spread because of the dependency caused the failure, eventually leading to paralysis of the entire system, such a structure more unstable compared to traditional architectures. To solve this problem, resulting in a series of circuit breakers and other protection services

In a distributed architecture, when a service unit fails, the fault monitoring circuit breaker, returns an error response to the caller, rather than the long wait. This does not make the thread due to a fault call service is prolonged occupation does not release, to avoid the spread of the fault in the distributed system

Hystrix have service degradation, service fuse, thread and signal isolation, request caching, request merging and service monitoring and other powerful features

Hystrix achieve isolation mode using bulkhead thread pool, it creates a separate thread pool for each dependent services, so even if the delay is too high a dependency service occurs, it is only an effect on the dependent services of call, not slow down other dependent services

Five, Spring Cloud core components: Zuul

Spring Cloud Zuul through integration with Spring Cloud Eureka, register itself as a service applications in Eureka governance, and access to information for all other examples of micro-services from Eureka in

For the maintenance of routing rules, Zuul will default to create a route map through the service name as ContextPath

Zuul provides a filter mechanism that can support the API Gateway attach no unified call to do a pre-filter for micro-service interface has been implemented to intercept and check for micro-services interface

VI Summary

  • Eureka: When each service starts, Eureka Client service will be registered with the Eureka Server, and Eureka Client can also turn to take the registry from Eureka Server pull, so they know where other services
  • Ribbon: the time between services initiated the request, based on the Ribbon to do load balancing, multiple machines from a service, select a
  • Feign: Based on the dynamic proxy mechanism Feign, according to the notes and selected machine, stitching request URL address and send a request
  • Hystrix: request is initiated by Hystrix thread pool to go, different services take a different thread pool to achieve the isolation of different service calls, to avoid the avalanche of service issues
  • Zuul: If the front end, back-end system to call the mobile terminal, the gateway into the Unified from Zuul, the gateway forwards the request to the corresponding Zuul service

Guess you like

Origin blog.csdn.net/xunjiushi9717/article/details/91988479