“This is the sixth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

We know that Spring Cloud can be used to develop microservices, but few people really know what Spring Cloud is.

The official explanation: Spring Cloud provides tools that allow developers to quickly build distributed applications, and these services work well in any distributed environment.

Now that we are providing some tools to quickly build microservices applications, what problems do we need to solve in the development of microservices?

  1. Service Registration Discovery

  2. Remote service invocation

  3. Load balancing

  4. The circuit breaker

  5. Distributed message

  6. Configuration center

  7. Link to monitor

Therefore, Spring Cloud provides some tools to solve this problem, such as Eureka/Consoul/ ZooKeeper for service registration; Remote calls encapsulate HTTP calls based on RestTemplate. Ribbon for load balancing and Hystrix for circuit breaker; Distributed message based on Kafka, rabbitMQ; Configuration center based on config; Link monitoring is based on SLEUTH.

However, there are some problems with components that spring does not provide, such as Eureka, Ribbon, and Hystrix, which are open sourced from Netflix. Kafka and ZooKeeper are standalone components that seem to have nothing to do with Spring. Yes, that’s the strength of the Spring team. They rarely duplicate the old wheels, but they use the wheels that someone else has built to make it easier for users to use.

For example, at the beginning, Spring only provided core functions of IOC and AOP, while ORM framework, cache framework, MVC framework, Spring only provided compatibility and support, so people said that Spring is a universal glue, can integrate a variety of frameworks.

Of course, Spring also replaced some technologies that didn’t work well in the market, such as Struts2. I remember when the company made Struts2 prone to bugs, spring MVC was created and quickly replaced Struts. Become the mainstream framework now.

So the same is true for Spring Cloud, which is not a framework because the core of Spring Cloud does not implement service registration, fuses, configuration centers, etc. It provides a standard specification. Spring Cloud Netflix is an implementation of the Spring Cloud specification.

Common service components

ø Fusion in each microservice, dependent on and serving other components.

The Ribbon, client load balancing, features region affinity and retry mechanisms.

Hystrix, client fault tolerant protection, features such as service degradation, service meltdown, request caching, request consolidation, dependency isolation.

Feign, declarative service invocation, is essentially Ribbon+Hystrix

Stream is message driven. It has Sink, Source, and Processor channels, and features subscription and publication, consumer group, and message partition.

Bus, message Bus, a Stream implementation with Config repository modification,

Sleuth, distributed service tracking, needed to figure out how TraceID and SpanID and sampling would integrate with ELK.

You do not need to rely on other components to start alone.

Eureka, service registry, features failure elimination, service protection.

Dashboards, Hystrix dashboards, monitor cluster mode and single point mode, where the cluster mode needs to be coordinated by collector Turbine.

Zuul, API service gateway, routing distribution and filtering.

Config, distributed configuration center, support local repository, SVN, Git, Jar configuration modes

Construction of the Spring Cloud ecosystem

The Spring Cloud ecosystem is built based on the Spring Boot micro-framework, so Spring Cloud can be said to integrate other frameworks based on Spring Boot. So what is Spring Boot or why should you integrate based on Spring Boot?

First of all, Spring Boot is not a new technology. It is based on the concept of “Convention Over Configuration” under the Spring framework. The goal is to make it easier and faster for developers to create standalone and production-level applications based on the Spring framework. Why is SpringBoot a microframework? If you’ve played with SpringBoot, you know that you can quickly build a Web project with very little configuration.

There are no new technologies in Spring Boot, so learning SpringBoot will be easier if you are familiar with the Spring framework.

Under the Spring Cloud ecosystem built around Springboot, there are currently two types of comparison or implementation, one is based on Netflix and the other is based on Alibaba.

About Spring Cloud Alibaba

In the previous stage, we finished talking about Dubbo components in Spring Cloud Alibaba ecosystem. Of course, we did not explain it based on the form of Spring Cloud Project, but on the form of components. The reason is that Spring Cloud is essentially an integration of components.

At present, Spring Cloud Alibaba has a relatively mature system in its ecosystem

  1. Dubbo is used to implement high performance Java RPC communication

  2. Nacos service registry discovery, configuration management, service management

  3. Sentinel flow control, fuse downgrading, system load protection

  4. RocketMQ distributed messaging system provides low-latency, highly reliable message publishing and subscription services

  5. Seata high performance microservices distributed transaction solution

  6. Alibaba Cloud OSS Object Storage Service (OSS) is a massive, secure, low-cost and highly reliable Cloud Storage Service provided by Alibaba Cloud.

  7. Alibaba Cloud SchedulerX is a distributed task scheduling product developed by Alibaba Middleware team, which supports periodic tasks and fixed time point triggering tasks.

  8. Alibaba Cloud SMS covers the world’s SMS service, friendly, efficient and intelligent interconnection communication capabilities, to help enterprises quickly build customer access channels.

On August 1, 2019, Spring-Cloud-Alibaba released the first graduation version (graduation from incubator warehouse) and released v2.1.0.release. The latest version is 2.2.1. Version 2.2.x is available for Spring Boot 2.2.x

In addition, compared to the Spring Cloud Netflix ecology, by 2020, archaus/hystrix/ribbon/zuul/turbine starter will enter maintenance mode, Going into maintenance mode means that the Spring Cloud team will not add new functionality to these modules, but will still fix security issues and some block-level bugs. But without new iterations, Spring Cloud Netflix can still be used.

Spring-cloud-netflix-projects -entering-maintenance-mode

The fundamental reason for entering the maintenance mode is that Netflix has little investment in the maintenance of Zuul, Ribbon and other projects, so Spring Cloud will put all these projects into the maintenance mode in Greenwich.

Of course, these components will have other component proxies with corresponding functions, some of which are still incubating. Some have already graduated, such as alibaba

The overall architecture of microservices

Spring Cloud Alibaba

SpringCloud is a collection of several frameworks, including nearly 20 sub-projects such as Spring-Cloud-Config and Spring-Cloud-bus. It provides solutions in the fields of service governance, service gateway, intelligent routing, load balancing, circuit breaker, monitoring and tracking, distributed message queue, configuration management and so on.

Through the Spring Boot style encapsulation, Spring Cloud shields the complex configuration and implementation principles, and finally gives developers a simple and easy to understand and deploy distributed system development kit.

Like Spring Cloud, Spring Cloud Alibaba is a microservices solution that contains the necessary components for developing distributed application microservices, making it easy for developers to use these components to develop distributed application services through Spring Cloud programming model.

Relying on Spring Cloud Alibaba, you only need to add some annotations and a little configuration, you can plug Spring Cloud application into Ali Micro service solution, and quickly build distributed application system through Ali 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: Take traffic as the entry point to protect the stability of services from multiple dimensions, such as flow control, fuse downgrading and system load protection.

RocketMQ: An open source distributed messaging system based on highly available distributed clustering technology that provides low-latency, highly reliable message publishing and subscription services.

Dubbo: This is not to say more, in the country is very widely used in a high-performance Java RPC framework.

Seata: Alibaba open source product, an easy-to-use high-performance microservices distributed transaction solution.

Arthas: An open source Java dynamic tracking tool based on bytecode enhancement technology.

Ali Commercial Components

As a commercial company, Alibaba launched Spring Cloud Alibaba, which went public in large part to help promote its own Cloud offerings by taking over the developer ecosystem. So in the open source community, there are a lot of private goods, I have used these components when WORKING in Ali, the overall ease of use and stability is very high.

Alibaba Cloud ACM: an application configuration center that centrally manages and pushes application configurations 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 Alibaba Middleware team, which provides second-level, precise timing (based on Cron expression) task scheduling service.

Nacos Service registry

Nacos provides unified configuration management, service discovery, and registration. Service registration and discovery functions are similar 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 own services through native API or openApi, and 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, and when services are found unavailable, dynamic offline of services can be implemented to prevent service consumers from sending requests to unhealthy services.

Configuration management

Traditional configuration management is implemented based on the configuration file in the project. When the configuration file changes, it needs to be redeployed. However, the dynamic configuration center can manage the configuration in a unified manner, making the configuration more flexible and efficient.

The dynamic configuration center can implement dynamic configuration of routing rules, traffic limiting rules, dynamic data sources, switches, and dynamic UI

Aollo/Diamond/Disconf is a well-known open source configuration center in China

The overall architecture of Nacos

The overall architecture of Nacos is relatively clear, which can be briefly analyzed from the following architecture diagram provided by the official.

Cloud native

Cloud native can literally be divided into cloud and native.

Cloud is the opposite of local. Traditional applications must run on local servers. Now popular applications run on the cloud, which includes IaaS, PaaS and SaaS.

“Native” means “native”. At the beginning of our application design, we considered that the application would run in the cloud environment in the future. We should make full use of the advantages of cloud resources, such as the flexibility and distributed advantages of ️ cloud service.