Home  >  Article  >  Java  >  What are the seven major components of Spring Cloud?

What are the seven major components of Spring Cloud?

青灯夜游
青灯夜游Original
2021-04-25 17:43:5222960browse

Spring Cloud seven major components: 1. Eureka component, which describes how the service is registered and where to register it; 2. Ribbon component; 3. Feign component, a declaration web service client; 4. Hystrix component; 5. Config component; 6. Zuul component; 7. Bus component.

What are the seven major components of Spring Cloud?

The operating environment of this tutorial: windows7 system, java8 version, DELL G3 computer.

Spring Cloud Family Bucket Component

Before introducing the Spring Cloud Family Bucket, I must first introduce Netflix. Netflix is ​​a great company. In Spring It plays an important role in the Cloud project. Netflix provides many components including Eureka, Hystrix, Zuul, Archaius, etc., which are crucial in the microservice architecture. Spring encapsulates a series of components based on Netflix , named: Spring Cloud Eureka, Spring Cloud Hystrix, Spring Cloud Zuul, etc. Each component is introduced below:

(1) Spring Cloud Eureka

We use microservices. The essence of microservices is the calling of various API interfaces. So how do we generate these interfaces and how do we call them after generating these interfaces? How to manage it?

The answer is Spring Cloud Eureka. We can register our own defined API interface to Spring Cloud Eureka. Eureka is responsible for service registration and discovery. If you have studied Zookeeper, you can understand it well. Eureka The role is similar to that of Zookeeper, which is the registration and discovery of services. The components that make up the Eureka system include: service registration center, service provider, and service consumer.

What are the seven major components of Spring Cloud?

The above picture describes (the picture comes from the Internet):

1. Master-slave replication of the service registration center composed of two Eureka service registration centers Cluster;
2. Then service provider registers, renews, offline services, etc. with the registration center;
3. Service consumer reports to Eureka The registration center pulls the service list and maintains it locally (this is also the mechanism of client discovery mode !);
4. Then service consumeraccording to the Eureka Service Registration Center Select a service provider from the obtained service list to consume services.

(2) Spring Cloud Ribbon

Spring Cloud Eureka describes how services are registered, where they are registered, and how service consumers obtain services from service producers. Information, but Eureka only maintains the relationship between service producers, registration centers, and service consumers. The real service consumer calls the data provided by the service producer through Spring Cloud Ribbon.

It is mentioned in (1) that the service consumer obtains the service list of the service producer from the registration center and maintains it locally. This way of client discovery mode allows the service consumer to choose the appropriate one. The node accesses the data provided by the service producer. This process of selecting the appropriate node is completed by Spring Cloud Ribbon.

Spring Cloud Ribbon client load balancer comes from this.

(3) Spring Cloud Feign

In the above (1) and (2), we have used the simplest way to realize the registration discovery and service invocation of the service. Operation, if you specifically use Ribbon to call services, you can feel that the way to use Ribbon is still a bit complicated, so Spring Cloud Feign came into being.

Spring Cloud Feign is a declarative web service client, which makes writing web service clients easier. Use Feign to create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations, Feign also supports pluggable encoders and decoders, Spring Cloud adds annotations for Spring MVC, Spring Web uses HttpMessageConverters by default, Spring Cloud integrates Ribbon and the load-balanced HTTP client Feign provided by Eureka .

It can be simply understood as: the emergence of Spring Cloud Feign makes the use of Eureka and Ribbon easier.

(4) Spring Cloud Hystrix

We learned about using Eureka for service registration and discovery in (1), (2), and (3). Use Ribbon implements load balancing calls of services, and we also know that using Feign can simplify our coding. However, these are not enough to achieve a highly available microservice architecture.

For example: When a service fails, and the caller of the service does not know that the service has failed, if the number of requests placed by the call continues to increase, it will eventually wait for the failed relying party to form a task accordingly. The backlog eventually led to the paralysis of its own services.

Spring Cloud Hystrix is ​​designed to solve this situation and prevent continuous access to a faulty service. The meaning of Hystrix is: circuit breaker. The circuit breaker itself is a switching device used for circuit protection in our homes to prevent current overload. When an electrical appliance in the line is short-circuited, the circuit breaker can switch the faulty electrical appliance in time to prevent Serious consequences such as overloading, heating or even fire may occur.

(5) Spring Cloud Config

When there were not many microservices, the configuration and management of various services were relatively simple, but when there are hundreds or thousands of microservice nodes When it gets up, the management of service configuration will become complicated.

In a distributed system, due to the huge number of services, in order to facilitate unified management and real-time updating of service configuration files, a distributed configuration center component is required. In Spring Cloud, there is the distributed configuration center component Spring Cloud Config, which supports the configuration service to be placed in the memory of the configuration service (that is, local), and also supports being placed in the remote Git repository. In the Cpring Cloud Config component, there are two roles, one is Config Server and the other is Config Client.

Config Server is used to store configuration attributes. The storage location can be Git warehouse, SVN warehouse, local files, etc. Config Client is used to read service attributes.

What are the seven major components of Spring Cloud?

(6) Spring Cloud Zuul

We use Eureka in Spring Cloud Netflix to implement the service registration center and service registration and Discovery; service consumption and load balancing are implemented through Ribbon or Feign between services; external configuration and version management of multiple application environments are implemented through Spring Cloud Config. In order to make the service cluster more robust, Hystrix's fusing mechanism is used to avoid the spread of faults caused by exceptions in individual services in the microservice architecture.

What are the seven major components of Spring Cloud?

Let’s first talk about some things that need to be done in this architecture and its shortcomings:

1. First of all, it destroys the stateless feature of the service. In order to ensure the security of external services, we need to implement permission control on service access. The permission control mechanism of open services will penetrate and pollute the business logic of the entire open service. The most direct problem this will bring is that it will destroy the service. The stateless characteristics of REST API in the cluster. From the perspective of specific development and testing, in addition to considering the actual business logic during work, additional sustainable control processing of interface access is also required.

2. Secondly, existing interfaces cannot be directly reused. When we need to access external services from an existing cluster access interface, we have to add verification logic to the original interface or add a proxy call to implement permission control. We cannot directly reuse the original interface. .
Faced with problems similar to the above, how should we solve them? Now let’s get to the main topic of this article: Service Gateway!

In order to solve the above problems, we need to extract things like permission control from our service units, and the most suitable place for these logics is at the front end of external access. We need a more A more powerful load balancing device is what this article will introduce in the future: service gateway.

Service gateway is an integral part of the microservice architecture. In the process of uniformly providing REST API to external systems through the service gateway, in addition to having service routing and load balancing functions, it also has permission control and other functions. Zuul in Spring Cloud Netflix plays such a role, providing front-door protection for the microservice architecture. At the same time, it migrates the heavier non-business logic content of permission control to the service routing level, so that the service cluster main body can have more capabilities. High reusability and testability.

(7) Spring Cloud Bus

In (5) Spring Cloud Config, the configuration files we know can be stored in Git and other places through Config Server, through Config Client reads it, but our configuration file cannot always remain unchanged. How to update it when our configuration file changes?

The simplest way is to re-obtain the Config Client, but Spring Cloud will never let you do this. Spring Cloud Bus provides an operation that allows us to re-acquire the service without shutting down the service. Update our configuration.

Spring Cloud Bus official meaning: message bus.

Of course, dynamically updating service configuration is only one use of the message bus, and there are many other uses.

What are the seven major components of Spring Cloud?

Summary

Spring Cloud has more components than these. Through the verbal introduction above, you should be able to roughly understand it. I understand, but the functions of each component are far more than those introduced above. Each component has many other functional points. I hope the introduction here can give you an introduction and don't be afraid of such a big concept of microservices.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of What are the seven major components of Spring Cloud?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn