We know that Spring Cloud can be used to develop microservices, but few people really know what Spring Cloud is.
The official explanation is: spring cloud provides some tools that allow developers to quickly build distributed applications. These services can work well in any distributed environment.
Now that we provide some tools to quickly build microservice applications, we need to understand what problems need to be solved in the process of microservice development?
- Service registration discovery
- Remote service call
- Load balancing
- breaker
- Distributed messaging
- Configuration Center
- Link monitoring
Therefore, spring cloud provides some tools to solve such problems, such as service registration provides Eureka/Consoul/zookeeper; remote calls are based on RestTemplate encapsulation for http protocol calls; load balancing uses Ribbon, circuit breakers use hystrix; distributed messaging is based on kafka, rabbitMQ; configuration center is based on config; link monitoring is based on sleuth.
However, from these components, we found some problems. These components are not provided by spring. For example, eureka, ribbon, and hystrix are open sourced by netflix. However, kafka and zookeeper are independent components, which seem to have nothing to do with spring. Yes, this is the strength of the spring team. They rarely repeat the early wheels, but they use wheels made by others to encapsulate them to make it more convenient for users to use.
To give a simple example, for example, at the earliest spring only provided the core functions of IOC and AOP, and like ORM framework, caching, MVC framework, spring only provided a kind of compatibility and support, so at that time everyone said that spring is a universal glue, you can Various frameworks are integrated.
Of course, spring will also replace some technologies that are not well done on the market, such as struts2. I remember that the company made struts2 often have various loopholes, so spring mvc was created and soon replaced struts. Become the mainstream framework now.
Therefore, the same is true for spring cloud. Spring cloud is not a framework, because the core of Spring Cloud does not implement functions such as service registration, fuse, and configuration center. It provides a standard specification. And Spring Cloud Netflix is an implementation of the Spring Cloud specification.
Common service components
Ø integrated into each microservice, depends on other components and provides services for them.
Ribbon , client load balancing, features include regional affinity and retry mechanism.
Hystrix , client-side fault-tolerant protection, features include service degradation, service fuse, request caching, request merging, and dependency isolation.
Feign , declarative service call, essentially Ribbon+Hystrix
Stream , message-driven, with three channels of Sink, Source, and Processor, with features such as subscription publishing, consumer group, and message partition.
Bus , message bus, a Stream implementation modified with the Config warehouse,
Sleuth , distributed service tracking, you need to figure out how TraceID and SpanID and sampling, and how to integrate with ELK.
Ø starts alone without relying on other components, it can do it single-handedly.
Eureka , service registration center, with features such as invalidation removal and service protection.
Dashboard , Hystrix dashboard, monitoring cluster mode and single point mode, the cluster mode requires the cooperation of the collector Turbine.
Zuul , API service gateway, functions include routing distribution and filtering.
Config , distributed configuration center, supports local warehouse, SVN, Git, Jar package configuration and other modes
The construction of Spring Cloud ecology
The ecology of Spring Cloud is built based on the spring boot micro-framework, so spring cloud can be said to be based on spring boot to integrate other frameworks, so what is spring boot or why should it be integrated based on spring boot?
First of all, spring boot is not a new technology. It is a product based on the concept of "Convention Over Configuration" under the spring framework. It is mainly to help developers create independent operation and product-level operations more easily and quickly. Application based on spring framework. Why is springboot a microframework? If you have played springboot, you should have a good experience, we can quickly build a web project with very little configuration.
There is no new technology in spring boot. If you are familiar with the spring framework, it will be easier to learn spring boot.
Under the spring cloud ecosystem built around springboot, there are currently two types of comparative or implementations, one is based on netflix and the other is based on alibaba.
Information about Spring Cloud Alibaba
In the previous stage, we finished talking about the Dubbo components in the Spring Cloud Alibaba ecosystem. Of course, we did not explain based on the form of spring cloud project, but based on the form of components. The reason is that spring cloud is essentially for each component. integrated.
At present, in the Spring Cloud Alibaba ecosystem, there is already a relatively mature system
- Dubbo used to implement high-performance Java RPC communication
- Nacos Service registration discovery, configuration management, service management
- Sentinel flow control, fuse degradation, system load protection
- RocketMQ distributed messaging system, providing low-latency, highly reliable message publishing and subscription services
- Seata High-performance microservice distributed transaction solution
- Alibaba Cloud OSS Ali cloud object storage service (Object Storage Service, referred to as OSS), Ali cloud mass is provided, secure, low-cost, highly reliable cloud storage service.
- Alibaba Cloud SchedulerX A distributed task scheduling product developed by the Ali middleware team, which supports periodic tasks and fixed-time trigger tasks.
- Alibaba Cloud SMS covers the world's short message service, friendly, efficient, and intelligent interconnected communication capabilities to help companies quickly build customer access channels.
On August 1, 2019, spring-cloud-alibaba released the first graduation version (graduated from the incubator warehouse) and released the V2.1.0.RELEASE version. The latest version is 2.2.1.RELEASE, 2.2. x version is suitable for Spring Boot 2.2.x
In addition, compared to the Spring Cloud Netflix ecosystem, by 2020, starters such as archaus/hystrix/ribbon/zuul/turbine will enter the maintenance mode. Entering the maintenance mode means that the spring cloud team will no longer add new functions to these modules. However, security issues and some block-level bugs will still be fixed. It's just that there is no new function iteration, spring cloud netflix can still be used.
Article link -> spring-cloud-netflix-projects-entering-maintenance-mode
The most fundamental reason for entering the maintenance mode is that Netflix has relatively little investment in the maintenance of projects such as zuul and ribbon, so Spring Cloud will put these projects into the maintenance mode in Greenwich.
Of course, these components will have other component agents with corresponding functions, and some of them are still in incubation. Some have graduated, such as alibaba standard
The overall architecture of microservices
Spring Cloud Alibaba
When it comes to microservices, I have to mention the Spring Cloud family bucket series. Spring Cloud is a collection of several frameworks, including nearly 20 sub-projects such as spring-cloud-config, spring-cloud-bus, etc. It provides service governance, service gateway, intelligent routing, Solutions in the fields of load balancing, circuit breakers, monitoring and tracking, distributed message queues, configuration management, etc.
Through Spring Boot style encapsulation, Spring Cloud shields complex configuration and implementation principles, and finally leaves a set of distributed system development toolkits that are simple to understand and easy to deploy for developers.
Like Spring Cloud, Spring Cloud Alibaba is also a set of microservice solutions, including the necessary components for developing distributed application microservices, so that developers can easily use these components to develop distributed application services through the Spring Cloud programming model.
Relying on Spring Cloud Alibaba, you only need to add some annotations and a small amount of configuration to connect Spring Cloud applications to Ali's microservice solutions, and quickly build a distributed application system through Ali's middleware.
Components included in Spring Cloud Alibaba
Ali open source components
Nacos: A dynamic service discovery, configuration management and service management platform that makes it easier to build cloud-native applications.
Sentinel: Regarding the flow as an entry point, it protects the stability of the service from multiple dimensions such as flow control, fuse degradation, and system load protection.
RocketMQ: an open source distributed messaging system, based on high-availability distributed cluster technology, provides low-latency, highly reliable message publishing and subscription services.
Dubbo: Needless to say, this is a high-performance Java RPC framework that is widely used in China.
Seata: Alibaba's open source product, an easy-to-use high-performance microservice distributed transaction solution.
Arthas: Open source Java dynamic tracking tool, based on bytecode enhancement technology, very powerful.
Ali commercial components
As a commercial company, Alibaba launched Spring Cloud Alibaba. To a large extent, the city hopes to help promote its own cloud products by seizing the developer ecosystem. So in the open source community, there are a lot of private goods. I have used this part of the component when I was working in Ali. The overall ease of use and stability are still very high.
Alibaba Cloud ACM: An application configuration center product that centrally manages and pushes application configuration in a distributed architecture environment.
Alibaba Cloud OSS: Alibaba Cloud Object Storage Service (OSS) is a cloud storage service provided by Alibaba Cloud.
Alibaba Cloud SchedulerX: A distributed task scheduling product developed by the Alibaba middleware team, which provides second-level, accurate timing (based on Cron expressions) task scheduling services.
Nacos Service Registration Center
Nacos provides unified configuration management, service discovery and registration. The functions of service registration and discovery are equivalent to zookeeper used in dubbo, or consoul and eureka used in spring cloud.
Service discovery and service health monitoring
Nacos provides RPC-based service discovery. Service providers can register their services through native API or openApi. Service consumers can use API or Http to find and discover services.
At the same time, Nacos provides real-time monitoring and inspection of services. When a service is found to be unavailable, it can dynamically offline the service to prevent service consumers from sending requests to unhealthy services.
Configuration management
Traditional configuration management is based on the configuration files in the project. When the configuration file changes, it needs to be redeployed. The dynamic configuration center can manage the configuration uniformly, so the configuration becomes more flexible and efficient.
The dynamic configuration center can realize dynamic configuration of routing rules, dynamic configuration of current limiting rules, dynamic data sources, switches, dynamic UI and other scenarios
The most famous open source configuration center in China: Aollo / diamond / disconf
The overall structure of Nacos
The overall structure of Nacos is relatively clear. We can make a simple analysis from the official structure diagram below.
Cloud native
From a literal point of view, cloud native can be divided into two parts: cloud and native
Cloud is the opposite of local. Traditional applications must run on the local server. Now popular applications run on the cloud. The cloud includes IaaS, PaaS, and SaaS.
Native is a native of meaning, we began to design the application to take into account when future applications are running inside a cloud environment, to take full advantage of cloud resources, such as ️ cloud services elastic and distributed advantage.
<img src="https://mic-blob-bucket.oss-cn-beijing.aliyuncs.com/202110291741029.webp" alt="img" style="zoom:60%;" />
Copyright statement: All articles in this blog, except for special statements, adopt the CC BY-NC-SA 4.0 license agreement. Please indicate the reprint from Mic takes you to learn architecture!
If this article is helpful to you, please help me to follow and like. Your persistence is the motivation for my continuous creation. Welcome to follow the WeChat public account of the same name for more technical dry goods!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。