Relationship between a preliminary

The image above is from the Spring website. As you can see, Spring is actually an ecosystem with many sub-projects, Such as Spring Framework, Spring Boot, Spring Cloud (and Spring Data, Spring Security, Spring Batch, Spring Session, Spring AMQP, etc.), Please go to the link:spring.io/projects

Spring in its broadest sense is an ecosystem, a collection of technologies. When we say Spring, we only mean Spring in a narrow sense. We actually mean the Spring Framework. We will cover Spring (Spring Framework), Spring Boot, and Spring Cloud in detail

introduce

Spring Framework

The Spring Framework is the cornerstone of the entire Spring ecosystem. It has two important design cores, IOC (Inversion of Control) and AOP (aspect oriented programming), on which Spring relies.

features

Two of the core features of the Spring Framework are the IOC container for managing our objects and the AOP aspect oriented programming to reduce repetitive coding. In addition, it also provides data storage, Wbe module development, resource management, data verification and binding, type conversion and internationalization.

advantages

  • Decouple code and simplify development. With the IOC container provided by the Spring Framework, users can leave dependencies between objects to the Spring Framework to manage, avoiding excessive program coupling caused by hard coding.
  • Support for AOP programming. AOP functionality provided by the Spring Framework facilitates section-oriented programming.
  • Support for declarative transactions. In the Spring Framework, the disadvantages of hard coding of programmatic transactions can be avoided, and transaction management can be implemented flexibly through declarative way, improving development efficiency and quality.
  • Make Java EE apis easier to use.

disadvantages

  • It takes a long time to get started with Spring.
  • Compatibility with outdated technologies, resulting in increased use complexity.
  • Too many configurations. XML configuration is no longer a popular way to configure a system.
  • When integrating third-party tools, programmers also need to consider compatibility between tools.
  • The system starts slowly and does not provide the hot deployment function. The system depends on the hot deployment of VMS or Web servers.

Spring Boot

Spring Boot is a new automated configuration solution. With SpringBoot, you can quickly create standalone applications based on Spring’s production level without much focus on XML configuration.

features

Spring Boot takes advantage of JavaConfig’s deployment mode and its design concept of “Convension Over Configuration” (COC). It provides a number of spring-boot-starter auto-configuration dependencies for enterprise application development scenarios right out of the box. (The official starter is named spring-boot-starter-xxx, while the unofficial starter is named xxX-spring-boot-starter.)

COC, Convension Over Configuration, or programming by convention, is a software design paradigm that convenes developers in reducing the number of decisions they have to make, reap the benefits of simplicity, not flexibility.

advantages

  • It integrates mainstream frameworks without configuration and automatically integrates third-party frameworks.
  • Spring projects can be run independently, and Spring Boot can be run independently in the form of JAR packages. The project can be successfully run using the java-jar command or by executing the main function in the project’s main function.
  • Embedded server, capable of rapid deployment. Integrates the Tomcat (default), Jetty, and Undertow containers.
  • There are many plugins that allow us to quickly build a Spring project out of the box and run a JavaEE project with very little configuration.
  • Pure Java configuration with no code generation and no XML configuration required. It also provides a series of non-functional generic configurations.
  • Significantly reduced development time and increased productivity.

Advantages are too many, here is only part of the list, we use all know.

disadvantages

  • Automatic configuration makes it difficult to locate faults.
  • Version iteration speed is too fast and some modules are changed too much.
  • Integration is too high, want to know the bottom cost is large.

SpringCloud

Spring Cloud is an ordered collection of frameworks that take advantage of the development convenience of Spring Boot to ingeniously simplify the development of distributed system infrastructures, providing development kits to provide service discovery registries, configuration centers, intelligent routing, message buses, circuit breakers, load balancing, and data monitoring.

features

Core elements of microservices Spring Cloud technology stack implementation
Service registration and discovery Eureka, Spring Cloud Alibaba Nacos, Spring Cloud Consul, Spring Cloud Zookeeper
Service configuration and management Spring Cloud Config、 Spring Cloud Alibaba Nacos
Service fuse Spring Cloud Netflix Hystrix、 Spring Cloud Alibaba Sentinel、 Spring Cloud Circuit Breaker Resilience4J
Service interface invocation (simplified tool for clients to invoke services) Spring Cloud OpenFeign
Client load balancing Spring Cloud Netflix Ribbon
Service Routing (API Gateway) Spring Cloud Netflix Zuul, Spring Cloud Gateway
Full link tracing Spring Cloud Sleuth
Event message bus Spring Cloud Bus
Distributed transaction Spring Cloud Alibaba Seata
message-driven Spring Cloud Stream

For more information please go to the link: Spring. IO /projects/sp…

Service registration and discovery

Comparison of registry selection

Nacos Eureka Consul Zookeeper Etcd SOFARegistry
language Java Java Go Java Go Java
website nacos.io Github.com/Netflix/eur… www.consul.io zookeeper.apache.org coreos.com/etcd www.sofastack.tech/projects/so…
Github Github.com/alibaba/nac… Github.com/Netflix/eur… Github.com/hashicorp/c… Github.com/apache/zook… Github.com/etcd-io/etc… Github.com/alipay/sofa…
CAP CP+AP AP CP CP CP AP
Service health check CP+AP AP CP CP CP AP
Kv storage service N/A N/A support support support N/A
Using interfaces (multilingual capability) gRPC / Dubbo / REST Client/HTTP Supports HTTP and DNS The client HTTP / gRPC Client (Java)
Watch support Long Polling/ most increments is supported Long Polling/ most increments is supported Full/Long Polling is supported support Support Long Polling Support (server push)
Spring Cloud integration support support support support support support
Dubbo integration support Does not support Does not support support support support

The gateway

Comparison of Gateway selection

Kong Spring Cloud Zuul (based on Zuul 1.x) Spring Cloud Gateway
introduce Nginx(OpenResty) + Lua plug-in, high performance Java + Servlet + Groovy(Hot Update) Java + Spring 5.0 + Reactor non-blocking
website konghq.com Github.com/Netflix/zuu… Spring. IO/projects/sp…
Github github.com/Kong/kong Github.com/Netflix/zuu… Github.com/spring-clou…
Developer divide Kong (Mashape) company Netflix Pivotal
The main purpose Enterprise API Management Microservice Gateway Microservice Gateway
Ease of development Lua scripting language, which is difficult Java + Servlet, easy Reactor asynchronous, difficult
Whether open source Open Source/Enterprise edition Open source Open source
Support agreement RESTful API RESTful API RESTful API
API registration/dynamic routing Managed through the Admin API Dynamic routing Dynamic routing
Current limiting support Need to develop support
fusing support Need other components support
retry support support support
Health check support support support
Load balancing algorithm Polling, hash Polling, random, weighted polling, custom Polling, random, weighted polling, custom
permissions Built-in multiple ways The development of implementation The development of implementation
Tracing support Need other components Need other components
Support Yaml support support support

Service configuration and management

Comparison of configuration center selection

Nacos Apollo Spring Cloud Config
language Java Java Java
website nacos.io Github.com/ctripcorp/a… Spring. IO/projects/sp…
Github Github.com/alibaba/nac… Github.com/ctripcorp/a… Github.com/spring-clou…
Configuring Real-time Push Support (HTTP long polling within 1s) Support (HTTP long polling within 1s) Support (Spring Cloud Bus)
Version management support support Support (Git)
Configure a rollback support support Support (Git)
Gray released Does not support support support
Rights management Does not support support Support (Git dependent)
Multiple clusters support support support
Many environmental support support support
Listening to the query support support support
multilingual A mainstream language that provides an Open API A mainstream language that provides an Open API Only support Java
Configuration format verification support Does not support Does not support

Service fuse

Comparison of circuit breaker selection

Sentinel Hystrix Resilience4j
language Java Java Java
website sentinelguard.io/zh-cn/ Github.com/Netflix/Hys… N/A
Github Github.com/alibaba/Sen… Github.com/Netflix/Hys… Github.com/resilience4…
The main purpose Semaphore isolation (concurrent thread flow limiting) Thread pool isolation/semaphore isolation Semaphore isolation
Fuse downgrading strategy Based on response time, exception ratio, number of exceptions Based on abnormal ratio Based on exception rate, response time
Real-time statistical implementation Sliding Windows (LeapArray) Sliding Windows (based on RxJava) Ring Bit Buffer
Dynamic Rule Configuration Support for multiple data sources Support for multiple data sources Support co., LTD.
scalability Multiple extension points Plug-in form Interface form
Annotation-based support support support support
Current limiting Based on QPS, traffic limiting based on call relationships is supported Limited support Rate Limiter
Traffic shaping Support preheating mode, constant speed mode, preheating queuing mode (can be configured in flow rules) Does not support Simple Rate Limiter mode
System adaptive protection support Does not support Does not support
The console Provides out-of-the-box console for configuring rules, viewing second-level monitoring, machine discovery, and more Simple monitoring view No console is provided, and other monitoring systems can be connected

Full link tracing

Comparison of link tracking model selection

CAT Zipkin Pinpoint Skywalking
language Java Java Java Java
website konghq.com zipkin.io/ Github.com/naver/pinpo… skywalking.apache.org/zh/
Github Github.com/dianping/ca… Github.com/openzipkin/… Github.com/naver/pinpo… Github.com/apache/skyw…
implementation Code burying points (interceptors, annotations, filters, etc.) Intercepts requests and sends (HTTP, MQ) data to the Zipkin service Java probe, enhanced bytecode Java probe, enhanced bytecode
Storage option Mysql, HDFS In-memory, Mysql, Cassandra, Elasticsearch HBase + Mysql Elasticsearch, H2, Mysql, TiDB
Communication mode NIO data transmission based on Netty HTTP, MQ Thrift gRPC
Invasion degree The larger The relatively small Bytecode probe technology, code non-invasive Bytecode probe technology, code non-invasive
MQ monitoring Does not support Does not support Does not support Support (RocketMQ, Kafka)
Global call statistics support support Does not support support
Trace the query Does not support support Does not support support
Call the police support Does not support support support
The JVM monitoring Does not support Does not support support support
advantages Fully functional. Spring-cloud-sleuth is a great way to integrate Zipkin, code is non-invasive, integration is very simple and the community is much more active. Completely non-invasive, only need to modify the startup mode, perfect interface, detailed functions. Completely non-invasive, perfect interface, support application topology and a single call chain query. With perfect functions (Zipkin + Pinpoint)
disadvantages 1. The code is highly intrusive and needs to be buried.

2. The document is in disorder, and the consistency between the document and the release version is low, so we need to rely on the review private server (or manually download the JAR from his private server and upload it to our private server).
1. By default, Http requests are used to report information to Zipkin, which consumes performance.

2. Combine Sleuth with RabbitMQ asynchronously, which increases the complexity. RabbitMQ is required.

3. Data analysis is relatively simple.
1. You cannot query a single call chain, which displays the call ecology of the entire application.

2. Secondary development is difficult
1. There are many bugs before version 3.2, and the compatibility is poor

2. Too many dependencies.
The document Online information is less, only the official website provided documents, relatively messy documentation documentation documentation

advantages

  • Spring Cloud provides a full suite of microservice functional components, many of which are essentially “out of the box” and are well compatible with each other, simplifying development.
  • The components that Spring Cloud integrates are basically lightweight and are the best in their field.
  • Components are decoupled from each other, giving developers the flexibility to choose and match different components.
  • Spring Boot based development, convention over configuration, annotation-based, no configuration files.

disadvantages

  • Compared with other RPC frameworks, Spring Cloud does not limit the communication protocols between services. Mainstream clients such as RestTemple and Feign directly support the Ribbon for service registration discovery and intelligent routing. The underlying communication protocol is HTTP. It is possible that the performance of service calls will be compromised relative to RPC frameworks such as Dubbo.
  • From the perspective of microservice development, too many microservices and high governance costs are not conducive to system maintenance. The high cost of distributed system development (fault tolerance, distributed transactions, etc.) is a big challenge for the team.

Relationship between revisited

The automatic configuration of Spring Boot is actually thanks to the @enable module driver of Spring Framework.

Framework implementations annotations Activate the module
Spring Framework @EnableTransactionManagement Transaction management module
@EnableWebMvc Web Mvc module
@EnableAspectJAutoProxy AspectJ module
@EnableCaching The cache module
@EnableEnableScheduling Scheduled task module
@EnableAsync Asynchronous processing module
@EnableMBeanExport JMX module
Spring Boot @EnableAutoConfiguration Automatic assembly module
@EnableConfigurationProperties Configure the property binding module
@EnableOAuth2Sso OAuth2 single sign-on module
@EnableManagementContext Physical modules
Spring Cloud @EnableDiscoveryClient Service discovery module
@EnableFeignCliens Feign client module
@EnableCircuitBreaker Service fuse module
@EnableEurekaServer Eureka server module
@EnableEurekaClient Eureka client module

The above table shows the @enable annotation module of some Spring Framework, Spring Boot and Spring Cloud. There are many other annotations that you can check for yourself. In fact, we can also use the @Enable annotation module to implement a custom Starter. Enable your own projects to be automatically configured.

conclusion

  • The Spring Framework is the cornerstone of the Spring ecosystem, and all other Spring modules depend on it.
  • Spring Boot is a new automated configuration solution driven by the @Enable annotation module of the Spring Framework. It solves the difficulty of getting started with the Spring Framework, shields many low-level details, and uses JavaConfig to solve many XML configuration troubles.
  • Sring Cloud is a set of micro-service development tools based on Spring Boot, which simplifies the development complexity of distributed projects by utilizing the automatic configuration feature of Spring Boot.

Spring -> Spring Boot -> Spring Cloud