Hello, today I would like to share Spring Cloud with you. Please take out your notebook and write it down.
What are microservices?
The concept of Microservices originated in an article “Microservices” written by Martin Fowler in March 2014. Microservices architecture is an architectural pattern that advocates the partitioning of a single application into a set of small services that coordinate with each other to provide ultimate value to users.
Advantages of microservices architecture
- Complexity control
By decomposing applications, we avoid the endless accumulation of complexity. Each microservice focuses on a single function and clearly expresses service boundaries through well-defined interfaces.
Due to its small size and low complexity, each microservice can be fully controlled by a small development team, making it easy to maintain high maintainability and development efficiency.
- Independent deployment
Because microservices have independent running processes, each microservice can also be deployed independently. There is no need to compile and deploy the entire application when a microservice changes.
Applications made up of microservices have a series of parallel distribution processes, making distribution more efficient, reducing the risk to the production environment, and ultimately shortening the application delivery time.
- Flexible technology selection
Under the microservice architecture, technology selection is decentralized. Each team is free to choose the most appropriate technology stack based on its own service needs and industry development status.
Because each microservice is relatively simple, the risk of upgrading the technology stack is low, and even a complete refactoring of a microservice is feasible.
- Fault tolerance
When a component fails, in the traditional single-process architecture, the failure is likely to spread within the process, resulting in global application unavailability.
In a microservice architecture, faults are isolated within a single service. If well designed, other services can achieve fault tolerance at the application level through retry, smooth degradation and other mechanisms.
- extension
Monolithic applications can also achieve horizontal scaling, where the entire application is replicated to different nodes. Microservices architectures are flexible when different components of an application have different scaling requirements, because each service can scale independently based on actual needs.
springboot
Spring Boot is a new framework from the Pivotal team designed to simplify the initial setup and development process for new Spring applications. The framework uses a specific way to configure so that developers no longer need to define boilerplate configurations.
To put it in my terms, Spring Boot is not a new framework, it has a lot of frameworks configured by default, just like Maven integrates all jars, Spring Boot integrates all frameworks (I don’t know if the analogy is appropriate).
Spring Boot simplifies spring-based application development by making it possible to create a stand-alone, production-level Spring application with a small amount of code. Spring Boot provides out-of-the-box setup for the Spring platform and third-party libraries so you can get started.
The core idea of Spring Boot is that convention is greater than configuration, and most Spring Boot applications require very little Spring configuration. Spring Boot is a great way to simplify your development model. It has components for all the common frameworks you want to integrate.
Spring characteristics of the Boot
- Create a stand-alone Spring application
- Embedded Tomcat, no need to deploy WAR files (Undertow is mostly used now)
- Simplifying Maven Configuration
- Automatic Spring configuration
- Provides production-ready functions such as metrics, health checks, and external configuration
- There is absolutely no code generation and no configuration requirement for XML
Spring Cloud Netflix(Netflix)
Core functional components:
- Configure the central SpringCloud Config
At present, SpringCloud Config is mainly used to make a configuration center through Git/SVN, from which each service obtains its own configuration parameters.
- Service Discovery — Netflix Eureka
Eureka, a service discovery framework developed by Netflix, is itself a REST-based service for locating services to enable cloud middle-tier service discovery and failover.
- Service Gateway — Netflix Zuul
As an API gateway in the microservices architecture, it supports dynamic routing and filtering functions.
- Service invocation, customer side load balancing — Netflix Ribbon
The Ribbon is an open source cloud middle-tier service project released by Netflix. Its main function is to provide clients with load balancing algorithms.
- Service downgrades, circuit breakers — Netflix Hystrix
Netflix is an open-source fault-tolerant framework that acts as a circuit breaker, requesting fuses and service downplays, providing near-real-time monitoring and alarms.
In addition to the basic components above, there are dozens of other tool frameworks.
The five components mentioned above are already at the elder level, except for much more useful alternatives.
Component selection can be alternative
Spring Cloud Alibaba
It is a one-stop solution for micro-service development provided by Alibaba and the integration of Alibaba open source middleware and Spring Cloud system.
Component selection instructions:
- Service a configuration: Config, Nacos
- Registries: Eureka (stop watch), Zookeeper, Consul (go language written), Nacos
- Service Gateway: Zuul, Gateway (by Spring itself) aims to provide a simple and efficient way to route apis and give them cross-domain attention, such as: security, monitoring/metrics, and resiliency.
- Service calls: Ribbon, LoadBalancer/Feign, OpenFeign
- Service degradation: Hystrix (cloud’s new service, which is still widely used in China, and its ideas are worth learning), Resilience4J (recommended by foreign countries instead of Hystrix), and Sentienl (produced by Ali)
- Service Bus: Bus (obsolete) Nacos (dynamic refresh of configuration)
- Message-driven: StreM-Spring components for integration with external messaging middleware to create bindings. For example, Kafka, RabbitMQ, RocketMQ.
- Distributed link tracking: APM tool Zipkin+Sleuth, Pinpoint, SkyWalking, CAT
Distributed transactions
Seata is an open source distributed transaction solution of Alibaba, committed to providing high performance and easy to use distributed transaction services under microservices. AT, TCC, SAGA and XA transaction modes are provided.
Better performance than LCN, will not cause deadlock; Without a management interface, data consistency cannot be ensured, only final consistency can be ensured.
Tx-lcn is positioned as a transaction coordination framework. The framework does not operate transactions itself, but achieves transaction consistency based on transaction coordination.
Ensure strong consistency of data; Performance is not particularly powerful and may cause deadlocks
10. Security Authentication :Security provides a set of primitives for building secure applications and services that are easy to use.
11. Distributed timed task: elastic-Job, XXl-job, Quartz, Saturn, Opencron, Antares
12. Monitor and Log: Prometheus, Grafana Loki,ELK(Elasticsearch+Logstash+Kibana)
Spring Cloud vs. Dubbo
Well, that’s all for today’s article, hoping to help those of you who are confused in front of the screen