springcloud life experience and role

Spring Cloud is a framework that integrates many open sources. It uses the development convenience of Spring Boot to realize service governance, service registration and discovery, load balancing, data monitoring, REST API publishing, etc. It basically includes all the distributed frameworks need. Function. It is a distributed development toolkit that is easy to open, deploy and maintain. Before getting a detailed understanding of the various components used in Spring Cloud, let's first understand the past and present of the microservice framework.

Monolithic Architecture 

In the early stage of website development, the traffic faced by the project is relatively small, and a single application can realize the functions we need, thereby reducing the difficulty of development, deployment and maintenance. This kind of data very important. 
write picture description here 
Vertical application architecture 
When the number of user visits continues to increase, a single application needs to continuously increase the number of servers to deal with, and at the same time, a single application is divided into multiple applications for processing to improve efficiency. This web framework (MVC) for accelerating web front-end loading plays a key role. 
At this stage, the system is often divided into different levels, and each level has corresponding responsibilities. The UI layer is responsible for interacting with users, the business logic layer is responsible for specific business functions, and the database layer is responsible for data exchange and storage with the upper layer. 
write picture description here
在这一阶段我们最常使用到的开发框架就是Spring(业务逻辑层管理POJO)+Struts(web层前置服务控制)+Hibernate(数据库层持久化)。
  • 1
  • 2

The service-oriented architecture is 
accompanied by the continuous improvement of the enterprise service volume. The deployment of the MVC framework leads to more and more load on the system, which cannot meet the requirements of concurrency, and the transmission of data and messages between systems will be frequently lost. At this time, we need to consider service-oriented architecture (SOA). SOA stands for Service Oriented Architecture. Divide the application into different modules according to different responsibilities (similar to the division of enterprises into different divisions), and different modules use specific call protocols (RPC) and interfaces to interact. 
In this way, the entire system is divided into many single component services to complete the request. When the traffic is too large, it is supported by horizontal expansion of the corresponding components, and all components meet the overall business needs through interaction. The advantage
of SOA as a service is that it can deploy, combine and use loosely coupled coarse-grained application components in a distributed manner through the network according to requirements. The service layer is the foundation of SOA and can be directly invoked by applications, thereby effectively controlling the artificial dependencies of the interaction with software agents in the system. The service-oriented architecture is a set of loosely coupled architecture. The principle of splitting services is high cohesion within services and low coupling between services. At this stage, WebService or dubbo can be used for service governance. Microservice architecture Microservice architecture is an extension of SOA architecture, which mainly focuses on the independence of individual services and smaller granularity of splitting. Compared with SOA architecture, microservices have the following advantages:  Microservices emphasize deeper componentization and serviceization, and each microservice can have an independent running space to ensure that each service component can be released as a separate product. Microservices abandon the cumbersome enterprise service bus of traditional SOA, and emphasize the use of HTTP REST API for external publishing. The segmentation granularity of microservices is large. After understanding the development process of the architecture, let's get to know Spring Cloud. 


write picture description here 

 





Spring Cloud comes from Spring and uses Spring Boot for fast development. Due to the large number of maintenance and support personnel in the Spring Cloud community, I believe that Spring Cloud will develop very well. Moreover, Spring Cloud basically uses the existing open source framework for integration, so the difficulty of learning and the threshold of deployment are relatively low, and it is easier to use and implement for small and medium-sized enterprises. 
What problem does Spring Cloud mainly solve? 
1. For enterprise-level SOA frameworks, the decoupling between services and services is a huge problem. With the continuous increase of functional services, the mutual calls between multiple services are frequent, and the calling process is like a messy ball of yarn , it is easy to lead to a situation that affects the whole body, often due to the lack of reasonable communication in the process of service update, resulting in data loss. 
At this time, service governance should be carried out, and the direct dependence between services should be transformed into the dependence of services on the service center. Eureka, the core component of Spring Cloud, solves this kind of problem. 
Eureka 
Eureka is an open source product of Netflix that provides service registration and discovery. It provides a complete implementation of Service Registry and Service Discovery. It is also one of the most important and core components of the Spring Cloud system. 
In the vernacular, Eureka is a service center. All the services that can be provided are registered to it for management. When other callers need it, go to the registration center to obtain it, and then call it, avoiding the direct connection between services. Called to facilitate subsequent horizontal expansion, failover, etc. As shown in the figure below: 
write picture description here 
Of course, if such an important component of the service center is suspended, it will affect all services. Therefore, it is necessary to build an Eureka cluster to maintain high availability. It is recommended to have at least two in production. 
As the traffic of the system continues to increase, a service needs to be expanded according to the situation. Eureka already provides the function of load balancing, and only needs to add the corresponding server instance. 
So what should I do if an instance hangs during the running of the system? Eureka content has a heartbeat detection mechanism. If an instance does not communicate within a specified time, it will be automatically removed, avoiding the impact of an instance hanging up. Serve. 
Therefore, using Eureka automatically has the functions of registration center, load balancing, and failover. 
Hystrix 
usually has multiple service layer calls in the microservice architecture. The failure of basic services may lead to cascading failures, resulting in the unavailability of the entire system. This phenomenon is called the service avalanche effect. 
The service avalanche effect is a process in which the unavailability of "service providers" leads to the unavailability of "service consumers" and gradually enlarges the unavailability. 
As shown in the following figure: A is the service provider, B is the service consumer of A, and C and D are the service consumers of B. The unavailability of A causes the unavailability of B, and when the unavailability snowballs to C and D, the avalanche effect is formed. 
write picture description here 
In this case, it is necessary for the entire service organization to have the function of fault isolation to prevent the failure of a certain service from affecting the overall situation. Hystrix components play this role in Spring Cloud. 
Hystrix will immediately notify the caller that the call fails when a service is called continuously for N times and does not respond, so as to prevent the caller from continuing to wait and affecting the overall service. Hystrix will check this service again at intervals and will continue to provide service if the service is restored. 
Hystrix Dashboard and Turbine 
need to respond quickly to solve the problem when the fuse occurs and avoid the further spread of the fault, so the monitoring of the fuse becomes very important. 
There are two tools for fuse monitoring: Hystrix-dashboard and Turbine 
Hystrix-dashboard is a tool for real-time monitoring of Hystrix. Through Hystrix Dashboard, we can intuitively see the request response time of each Hystrix Command, request success rate and other data . 
But if you only use Hystrix Dashboard, you can only see service information in a single application, which is obviously not enough. 
We need a tool that allows us to aggregate data from multiple services in the system and display it on the Hystrix Dashboard, and this tool is Turbine. 
The effect diagram of the monitoring is as follows: 
write picture description here 
If you want to know which indicators are monitored and how to monitor, you can refer to this article: Circuit Breaker Monitoring Hystrix Dashboard and Turbine 
Configuration Center 
As the number of microservices continues to increase, each microservice has its own corresponding configuration document. In the research and development process, there are test environments, UAT environments, and production environments, so each microservice corresponds to at least three configuration files for different environments. 
With so many configuration files, if you need to modify the configuration information of a public service, such as cache, database, etc., it will inevitably cause confusion. At this time, you need to introduce another component of Spring Cloud: Spring Cloud Config. 
Spring Cloud Config 
Spring Cloud Config is a configuration management solution for distributed systems. It includes two parts: Client and Server. Server provides storage of configuration files and provides the content of configuration files in the form of interfaces. Client obtains data through interfaces and initializes its own application based on this data. 
In fact, the server side serves all the configuration files, and the service instance of the configuration file needs to go to the Config Server to obtain the corresponding data. Organize all configuration files uniformly to avoid fragmentation of configuration files. 
If the configuration file is changed during service operation, the service will not get the latest configuration information. To solve this problem, Refresh needs to be introduced. It can reload configuration files during the runtime of the service. 
When all configuration files are stored in the configuration center, the configuration center becomes a very important component. 
If there is a problem with the configuration center, it will lead to catastrophic consequences. Therefore, it is recommended to cluster the configuration center in production to support the high availability of the configuration center. 
Although the Refresh solution on Spring Cloud Bus 
can solve the problem of overloading configuration information during the operation of a single microservice, in real practical production, there may be more than N services that need to update the configuration. 
If you rely on manual Refresh every time, it will be a huge workload. At this time, Spring Cloud proposes another solution: Spring Cloud Bus.
Spring Cloud Bus connects distributed nodes through a lightweight message broker. This would be used to broadcast state changes (eg configuration changes) or other message commands. 
A core idea of ​​Spring Cloud Bus is to extend Spring Boot applications through distributed starters, which can also be used to establish communication channels between one or more applications. The only way to do it so far is to use an AMQP message broker as a channel. 
Spring Cloud Bus is a lightweight communication component that can also be used in other similar scenarios. With Spring Cloud Bus, when we change the configuration file and submit it to the repository, it will automatically trigger the Refresh of the corresponding instance. The specific workflow is as follows: The 
write picture description here 
service gateway 
is in the microservice architecture mode, and the number of instances of the backend service is general. It is dynamic, and it is difficult for the client to find the access address information of the dynamically changed service instance.
Therefore, in order to simplify the front-end calling logic in microservice-based projects, API Gateway is usually introduced as a lightweight gateway. At the same time, API Gateway will also implement related authentication logic to simplify the complexity of calling each other between internal services.

The technology that supports the landing of API Gateway in the Spring Cloud system is Zuul. Spring Cloud Zuul routing is an integral part of the microservice architecture, providing edge services for dynamic routing, monitoring, resilience, security, and more. 
Zuul is a JVM-based routing and server-side load balancer produced by Netflix. 
Its specific role is to service forwarding, receiving and forwarding all internal and external client calls. Using Zuul can be used as a unified access entry for resources, and at the same time, some similar functions can be performed on the gateway. 
Link tracking 
As there are more and more services, the analysis of the call chain will become more and more complicated, such as the call relationship between services, the call chain corresponding to a request, and the time spent between calls. Monitoring becomes a problem. 
In actual use, we need to monitor various indicators of communication between services and services. These data will be the main basis for us to improve the system architecture. 
Therefore, distributed link tracking becomes very important, and Spring Cloud also provides specific solutions: Spring Cloud Sleuth and Zipkin.

Spring Cloud Sleuth provides link tracing for calls between services. Through Sleuth, you can clearly understand which services a service request has passed through, and how long each service takes to process. This allows us to easily sort out the calling relationship between microservices. 
Zipkin is an open source project of Twitter that allows developers to collect monitoring data on Twitter's various services and provide query interfaces. 
To sum up 
, let's take a look at how the various components of Spring Cloud are used together:

As can be seen from the above figure, the various components of Spring Cloud cooperate with each other and cooperate to support a complete set of microservices architecture. 
Among them, Eureka is responsible for the registration and discovery of services, and it is very good to connect each service. 
Hystrix is ​​responsible for monitoring the invocation between services, and it fails for many consecutive times for fuse protection. 
Hystrix dashboard, Turbine is responsible for monitoring the fuse situation of Hystrix, and provides a graphical display 
Spring Cloud Config provides a unified configuration center service 
When the configuration file changes, Spring Cloud Bus is responsible for notifying each service to obtain the latest configuration information. 
All external We all forward the requests and services through Zuul, which acts as an API gateway. 
Finally, we use Sleuth+Zipkin to record all the request data, which is convenient for us to carry out subsequent analysis. 
Spring Cloud has considered most of them from the beginning of the design. Functions required for the evolution of Internet company architecture, such as service discovery registration, configuration center, message bus, load balancing, circuit breaker, data monitoring, etc. 
These functions are provided in the form of plug-in, so that we can reasonably select the required components for integration in the process of system architecture evolution, so that the process of architecture evolution will be smoother and smoother. 
Microservice architecture is a trend. Spring Cloud provides a standardized, full-stop technical solution, which may be comparable to the birth of the current Servlet specification, effectively promoting the technical level of server-side software systems.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518055&siteId=291194637