Author |
YourBatman, senior architect in the field of online education,
Leng Leng, an open source contributor to the Spring Framework, Yunji architect, pig leader of the open source project, Spring Cloud Alibaba Committer
Source | Alibaba Cloud Native Official Account
The Spring Cloud 2020.0.0
version was officially released late at night on December 22, 2020 Beijing time . 2020.0.0 is the first Spring Cloud release using the new version naming scheme. In addition to a more developer-friendly naming method that is visible to the naked eye, this release completely abandoned the Netflix technology stack and is a long-term maintenance major version. What does this mean for developers? Today we invited YourBatman and Spring Cloud Alibaba committer, active authors in the open source community, to coldly explain the important changes in this release, and more importantly, talk to you about how we should respond as developers in the future .
Spring Cloud version management
Before the official release of Spring Cloud 2020.0.0, Spring Cloud's Release Train name was named after the London Underground station name and arranged in alphabetical order, such as: Hoxton, Greenwich, Ilford, etc. There are two such naming methods Fatal problem:
-
It is very unfriendly to non-English speaking countries, such as China, and cannot quickly sort out the relationship between version numbers
- There are only 26 English letters. What if the version number reaches Z? How to continue to develop?
Spring Cloud follows the Pivotal OSS support policy agreement to provide three years of support for the main version . In addition, after the major or minor version of Spring Cloud is released, if there are serious bugs and security issues, it will be maintained for a period of time (6-12 months). Refer to the following table:
Interpretation of core changes
As a major version , Spring Cloud 2020.0.0 has brought many significant changes. Among them, some blocking updates (not backward compatible) are the biggest highlight of this article. Come and serve.
Core change 1: Goodbye, Netflix
As early as 2018, Spring Cloud announced in its Roadmap some libraries/versions that will end , the most important of which is that the Spring Cloud Netflix project enters maintenance mode , and then plans to completely remove it in 2020.
Spring Cloud's decision to make such a decision is not necessarily active. We know that Spring Cloud has always regarded the Netflix OSS
package as its official default one-stop solution. At that time, the Netflix OSS package could hardly be equated with Spring Cloud. And Netflix announced around 2018 that its core components Hystrix, Ribbon, Zuul, Archaius, etc. have all entered maintenance status .
Today, Spring Cloud 2020.0 has been officially released. In this major version, the plan is finally spring-cloud-netflix
ready to go. I helped you draw a spring-cloud-netflix-dependencies
comparison chart of the main differences before and after the xml file, which is clear at a glance:
- The old version
spring-cloud-netflix-dependencies
managed all Netflix components, including Hystrix, Ribbon, Zuul, Eureka, etc. Since version 2020.0 it has and only manages Eureka (including Server and Client).
Core change 2: Continue to formulate industry standards and improve abstract definitions
Probably for most Spring Cloud application developers, they are spring-cloud-commons
probably new to modules. As the core of the Spring Cloud technology stack, this module provides a unified abstraction of the most important service registration and discovery, load balancing, and context management of the entire solution. spring cloud alibaba
The implementation of spring-cloud-commons
the whole family bucket is a concrete realization. This version makes a jump to the default startup language of the launcher above and the core code of the load balancer.
spring-cloud-commons
├── actuator
├── circuitbreaker
├── discovery
├── hypermedia
├── loadbalancer
└── serviceregistry
Core change three: push reactive asynchronous system
reactor is the implementation framework of reactive ( reactive programming ) and the work of the Pivotal team.
Both Spring Cloud Gateway and Spring Cloud Loadbalancer are built on reactor programming.
In addition, Josh Long, the official evangelist of Spring, recently published a book "Reactive Spring". If you want to learn more about reactor, you might as well read it.
Core Change 4: Better Embrace Cloud Native Capabilities
Spring Cloud 2020 is built on Spring Boot 2.4 and has a stronger configuration file processing mechanism that can be very well adapted to cloud native (for example, kubernetes configMap can be directly applied) configuration; built-in Docker image construction and hierarchical analysis and optimization capabilities.
If the team is using kubernetes, it spring-cloud-kubernetes
will also be a good alternative to Netflix.
Component alternatives
Since Spring Cloud has cut off the Netflix suite drastically, there must be an alternative. That is inevitable, the Spring Cloud team recommended us components for replacement:
Spring Cloud LoadBalancer
Among the above alternatives, you may be the strangest and most curious thing is Spring Cloud Loadbalancer
that it was only a small project in the Spring Cloud incubator , and it was once stranded. After restarting, developing, and making it its great mission, it was officially used to completely replace Ribbon and become the only implementation of Spring Cloud load balancer .
As shown in the figure, the load balancing abstract LoadBalancerClient
interface has two implementations, and after the Spring Cloud 2020.0 version, it BlockingLoadBalancerClient
is the only implementation.
Spring Cloud LoadBalancer currently only supports polling load balancing strategies, which is too simple compared to Ribbon's multiple high-availability strategies.
Spring Cloud Circuit Breaker
Circuit Breaker provides an abstraction compatible with the implementation of multiple circuit breaker components, allowing developers to choose the most familiar circuit breaker component for business development.
Here we mainly introduce Sentinel and Resilience4j. Sentinel is an important component of Spring Cloud Alibaba. By introducing spring-cloud-starter-alibaba-sentinel, you can have the ability to fuse downgrade and flow control, and provide a graphical console. As a similar component, Resilience4j is based on The functionally designed lightweight fault-tolerant library provides fusing, current limiting, and isolation capabilities. However, the official spring-cloud-starter-circuitbreaker-resilience4j plug-in has limited capabilities and cannot be directly managed by the console (if monitoring is required, additional Micrometer service).
Spring Cloud Alibaba adaptation
- Due to the dependence on Ribbon components, the latest Spring Cloud Alibaba 2.2.3 is not fully compatible with Spring Cloud 2020, and only needs to be fine-tuned.
// 排除 Ribbon (当然也可以排查 maven 依赖)
@EnableAutoConfiguration(excludeName =
"org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration")
- Increase spring cloud loadbalancer dependency.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
- The services involved in loading the configuration center need to start bootstrap (2020 is closed by default).
<!--增加此依赖即可完成启动-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
- You can refer to the above adjustments adapted Spring Cloud 2020 Compatible example .
How developers face and embrace change
As mentioned above, Spring Cloud provides powerful encapsulation and abstraction capabilities, such as encapsulation spring-cloud-circuit-breaker
of common fault-tolerant components, and there is no need to consider @hystrixcommand``@SentinelResource
component native annotations during use .
public static class DemoControllerService {
private RestTemplate rest;
private CircuitBreakerFactory cbFactory;
public String slow() {
return cbFactory.create("slow").run(() -> rest.getForObject("/slow", String.class), throwable -> "fallback");
}
}
-
Implementing component changes through such abstract bottom layers has little impact on users who use Spring Cloud Family Bucket at the upper level (for example, "Spring Cloud Alibaba Migration Guide: Zero Code Migration from Eureka to Nacos").
- About learning
spring-cloud-commns
I do not recommend directly read the source code (the code is easy discouraging part reactor), it is recommended to achieve a specific form of DEBUG debugging (for exampleNacosDiscoveryClient
), the core code, but a hundred lines.
- So for developers, whether before
Netflix
or chooseAlibaba
a technology stack, the core or graspspring-cloud-commons
abstract master Spring Cloud standards is particularly important.
to sum up
Spring Cloud 2020.0.0 is the main version of Spring Cloud. It is a very important existence, and upgrades and changes are huge. This is particularly reflected in the removal of all Netflix modules, the change of Spring Cloud startup mode, and so on. With the release of Spring Boot 2.4.x and Spring Cloud 2020.0, and the abandonment of the Netflix OSS suite, you will enter a new in- depth programming experience, full of surprises, and I am looking forward to it.
Of course, we still highly recommend everyone to use Spring Cloud Alibaba Family Bucket. At present, Spring Cloud Alibaba has been open source for two years and has graduated from the official. Not only is it eye-catching in terms of attention and activity, but also through the release of the Know Action Lab start.aliyun.com Provide sandbox and Java engineering scaffolding , Arthas code diagnosis tool, etc. to become the most complete Spring Cloud implementation of the tool chain.
Data Sources:http://www.gharchive.org/ GitHub developer behavior data
activity calculation formula in the past 2 years :https://github.com/X-lab2017/github-analysis-report-2019/blob/master/REPORT.md
Recommended reading
- How to smoothly migrate the registry from Eureka to Nacos?
-
Spring Cloud Alibaba Migration Guide 1: Zero code migration from Eureka to Nacos
-
Leader Education Microservice System Solar Part 3: Nacos Enterprise-level Landing Part 1
- Comparison of Sentinel and Hystrix
- Guideline: Migrating from Hystrix to Sentinel