SpringCloud Getting Started Notes

Spring Cloud

Since Spring Cloud released the first Angel.SR5 version in January 2016, it has been 4 years since the Hoxton.SR3 version was released in March 2020. In the past 4 years, Spring Cloud has released a total of 46 versions, and the number of supported components has increased from 5 to 21. Spring Cloud announced the follow-up RoadMap in December 2019:

  • The next version, the Ilford version, is a major version. This version is based on Spring Framework 5.3 & Spring Boot 2.4 and will be released around Q4 2020;
  • The Ilford version deletes projects in maintenance mode. Most of the Netflix projects currently in maintenance mode will be deleted (the spring-cloud-netflix Github project has deleted these maintenance mode projects);
  • Simplify the Spring Cloud release train. Subsequent Spring Cloud projects corresponding to IaasS vendors will be moved out of the Spring Cloud organization and maintained separately (spring-cloud-azure has always been maintained separately, and spring-cloud-alibaba is incubated in the Spring Cloud organization and maintained separately after graduation);
  • API refactoring will bring major changes (Spring Cloud Hoxton version adds Spring Cloud Circuit Breaker programming model for unified fusing operation and Spring Cloud Load Balanacer to handle client load balancing and replace Netflix Ribbon).

This RoadMap can be said to be a very big change to Spring Cloud.

SpringCloud alternative implementation

Insert picture description here

SpringCloud Alibaba

Component

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.

Nacos : A dynamic service discovery, configuration management and service management platform that makes it easier to build cloud-native applications.

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 : Apache Dubbo™ is a high-performance Java RPC framework.

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

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 massive, secure, low-cost, and highly reliable cloud storage service provided by Alibaba Cloud . You can store and access any type of data in any application, any time, and any place.

Alibaba Cloud SchedulerX : A distributed task scheduling product developed by the Alibaba middleware team, which provides second-level, accurate, highly reliable, and highly available timing (based on Cron expressions) task scheduling services.

Alibaba Cloud SMS : A global SMS service, friendly, efficient, and intelligent interconnected communication capabilities, helping companies quickly build customer access channels.

Spring Cloud technical points

Eureka: Service registration and discovery, used for service management.

Feign: Web call client, which can simplify the call of HTTP interface.

Ribbon: Client-based load balancing.

Hystrix: Fuse downgrade to prevent service avalanche.

Zuul: Gateway routing, which provides functions such as routing forwarding, request filtering, current limiting and downgrading.

Config: Configuration center, distributed configuration management.

Sleuth: Service link tracking

Admin: health management

Overview of service evolution

  1. Evolution from traditional services to microservices.

  2. Monolithic Application -> SOA -> Microservice (Let's talk about it below)

课外扩展:
持续集成,持续部署,持续交付。
集成:是指软件个人研发的部分向软件整体部分集成,以便尽早发现个人开发部分的问题;
部署: 是代码尽快向可运行的开发/测试节交付,以便尽早测试;
交付: 是指研发尽快向客户交付,以便尽早发现生产环境中存在的问题。
   如果说等到所有东西都完成了才向下个环节交付,导致所有的问题只能在最后才爆发出来,解决成本巨大甚至无法解决。而所谓的持续,就是说每完成一个完整的部分,就向下个环节交付,发现问题可以马上调整。使问题不会放大到其他部分和后面的环节。
   这种做法的核心思想在于:既然事实上难以做到事先完全了解完整的、正确的需求,那么就干脆一小块一小块的做,并且加快交付的速度和频率,使得交付物尽早在下个环节得到验证。早发现问题早返工。

上面的3个持续,也都随着微服务的发展而发展,当架构师的同学,可以参考这种方式。

持续集成的工具,向大家推荐:https://jenkins.io/doc/book/pipeline/

Monolithic application

  1. Concept: All functions are packaged together. Most of the application is a war package or jar package. The initial structure of my participation in online car-hailing is: a passenger project has functions such as users, orders, messages, and maps. As the business develops and functions increase, this project will become more and more bloated.

  2. Benefits: Easy to develop, test, and deploy, suitable for initial trial and error of the project.

  3. harm:

    ​ As the project becomes more and more complex, the team continues to expand. The disadvantages are revealed.

    • High complexity: a lot of code, one hundred thousand lines, one million lines level. Adding a small function will bring hidden dangers to other functions because they are together.
    • Technical debt: the flow of personnel, it is not broken and not repaired, because it is afraid to repair it.
    • Difficulty in continuous deployment: Because it is a full application, changing a small function and deploying all of it will cause unrelated functions to be suspended. It takes a long time to compile and deploy online, and they dare not deploy casually, resulting in low deployment frequency, which in turn leads to more functional changes between two deployments, and the less they dare to deploy, a vicious circle.
    • Poor reliability: A small problem, such as OOM in a small function, will cause the entire application to crash.
    • Restricted expansion: It can only be expanded as a whole, and cannot be expanded as needed. It cannot be properly distinguished according to the calculation-intensive (order dispatch system) and the IO-intensive (file service).
    • Obstructing innovation: Monolithic applications use one technology to solve all problems, and it is not easy to introduce new technologies. But in the development of the high-speed Internet, the trend of adaptation is: do the right things in the right language. For example, in a monolithic application, a project uses spring MVC and wants to switch to spring boot. The switching cost is very high, because there may be 100,000 or a million lines of code to be changed, and microservices can be easily switched because each service The function is simple and the code is small.

SOA

对单体应用的改进:引入SOA(Service-Oriented Architecture)面向服务架构,拆分系统,用服务的流程化来实现业务的灵活性。服务间需要某些方法进行连接,面向接口等,它是一种设计方法,其中包含多个服务, 服务之间通过相互依赖最终提供一系列的功能。一个服务 通常以独立的形式存在于操作系统进程中。各个服务之间 通过网络调用。但是还是需要用些方法来进行服务组合,有可能还是个单体应用。

Therefore, the introduction of microservices is a concrete practice of SOA thinking.

Microservice architecture = 80% SOA service architecture thinking + 100% componentized architecture thinking

Microservice

Microservice overview

  • No strict definition.
  • Microservice is an architectural style that divides a single application into small service units.
  • Microservice architecture is a way to develop a single application using a series of services with smaller granularity; each service runs in its own process; the services use a lightweight way to communicate (usually HTTP API); these services It is independently deployed based on business logic and scope through an automated deployment mechanism, and centralized management of services should be minimal, that is, each service can be written in different programming languages ​​and use different data storage technologies.
  • English definition:
看这篇文章:
http://www.martinfowler.com/articles/microservices.html
  • Small analogy

    Together for a long time will be divided. Communication after separation, independent deployment and independent storage.

分封制:
服从天子命令:服从服务管理。
有为天子镇守疆土的义务:各自完成各自的一块业务。
随从作战:服务调用。
交纳贡献:分担流量压力。
  • Duan (China-Taiwan Strategy)
Q:大师大师,服务拆多了怎么办?
A:那就再合起来。
Q:那太没面子了。
A:那就说跨过了微服务初级阶段,在做中台(自助建站系统)。

Microservice characteristics

Run independently in its own process.

A series of independent services together build the entire system.

A service only focuses on its own independent business.

Lightweight communication mechanism RESTful API

Development in different languages

Fully automatic deployment mechanism

Introduction to microservice components

Not limited to specific microservice implementation technologies.

  • Service registration and discovery: The service provider registers its calling address to the service registry, so that the service caller can easily find itself; the service caller finds the address of the service he needs to call from the service registry.

  • Load balancing: The service provider generally provides services in the form of multiple instances. The load balancing function allows the service caller to connect to the appropriate service node. Moreover, the process of service node selection is transparent to the service caller.

  • Service gateway: The service gateway is the only entry point for service invocation. In this component, functions such as user authentication, dynamic routing, gray release, A/B testing, and load current limiting can be implemented.

    灰度发布(又名金丝雀发布)是指在黑与白之间,能够平滑过渡的一种发布方式。在其上可以进行A/B testing,即让一部分用户继续用产品特性A,一部分用户开始用产品特性B,如果用户对B没有什么反对意见,那么逐步扩大范围,把所有用户都迁移到B上面来。灰度发布可以保证整体系统的稳定,在初始灰度的时候就可以发现、调整问题,以保证其影响度。
    
  • Configuration Center: Register localized configuration information (Properties, XML, YAML, etc.) in the configuration center to realize the indiscriminateness of the package in the development, testing, and production environment, facilitate the migration of the package, and is also a stateless feature.

  • Integration framework: All microservice components provide services to the outside in a single-duty package. The integration framework integrates all microservice components (especially management-side components) into a unified interface framework in the form of configuration, allowing users to be in a unified interface Use the system. Spring Cloud is an integrated framework.

  • Call chain monitoring: Record the connection and call relationship of completing a request, and display this serial or parallel call relationship. When the system goes wrong, you can easily find the point of error.

  • Supporting platform: After the system is micro-serviced, each business module is split and becomes more detailed. The deployment, operation and maintenance, and monitoring of the system are more complicated than the single application architecture, which requires automation of most of the work. Now, Docker and other tools can bring more convenience to the deployment of microservice architecture, such as continuous integration, blue-green release, health check, performance monitoring, and so on. If there is no suitable supporting platform or tools, the micro-service architecture will not be able to exert its maximum effect.

    1. 蓝绿部署是不停老版本,部署新版本然后进行测试,确认OK,将流量切到新版本,然后老版本同时也升级到新版本。
    2. 灰度是选择部分部署新版本,将部分流量引入到新版本,新老版本同时提供服务。等待灰度的版本OK,可全量覆盖老版本。
    
    灰度是不同版本共存,蓝绿是新旧版本切换,2种模式的出发点不一样。
    

Advantages of microservices

  1. Independent deployment. It does not rely on other services, has low coupling, and does not care about the impact of the deployment of other services on itself.
  2. Easy to develop and maintain: Focus on specific business, so the business is clear, the amount of code is small, and the module becomes easy to develop, understand, and maintain.
  3. Start block: There are few functions and few codes, so the startup is fast, there are services that need to be shut down for maintenance, and services will not be suspended for a long time.
  4. Partial modification is easy: only need to deploy the corresponding service, suitable for agile development.
  5. Unlimited technology stack: java, node.js, etc.
  6. On-demand scaling: a certain service is limited, memory, cpu, etc. can be added as needed.
  7. Single responsibility. The dedicated team is responsible for the specialized business, which is conducive to the division of labor.
  8. Code reuse. No need to rewrite. The underlying implementation is provided through an interface.
  9. Facilitate team collaboration: Each team only needs to provide an API. After the API is defined, it can be developed in parallel.

Disadvantages of microservices

  1. The inherent complexity of distributed: fault tolerance (a service downtime), network delay, call relationships, distributed transactions, etc., will bring complexity.

  2. The challenge of distributed transactions: each service has its own database. The point is that different services can choose the database that suits their business. Use MySQL for orders, Mongodb for comments, etc. The most ideal solution at present is: the ultimate consistency of flexible transactions.

    刚性事务:遵循ACID原则,强一致性。
    柔性事务:遵循BASE理论,最终一致性;与刚性事务不同,柔性事务允许一定时间内,不同节点的数据不一致,但要求最终一致。
    
    BASE 是 Basically Available(基本可用)、Soft state(软状态)和 Eventually consistent (最终一致性)三个短语的缩写。BASE理论是对CAP中AP的一个扩展,通过牺牲强一致性来获得可用性,当出现故障允许部分不可用但要保证核心功能可用,允许数据在一段时间内是不一致的,但最终达到一致状态。满足BASE理论的事务,我们称之为“柔性事务”。
    
  3. The cost of interface adjustment is high: if an interface is changed, the caller must change it.

  4. Increased difficulty of testing: an interface change, all callers have to test. Automated testing becomes important. The management of API documentation is also particularly important. Recommend: yapi.

  5. High operation and maintenance requirements: dozens of hundreds of services need to be maintained. Monitoring becomes complicated. And also pay attention to multiple clusters, unlike the original single, one application can run normally.

  6. Duplicate work: For example, java tool classes can be shared in common.jar, but it doesn’t work in multiple languages. C++ cannot directly use java jar packages.

Design Principles

Single responsibility principle: Focus on a separate and bounded part of the entire system function.

Service autonomy principle: it can be independently developed, tested, built, deployed, run, and decoupled from other services.

Lightweight communication principles: light, cross-platform, and cross-language. REST, AMQP, etc.

Granularity control: Combine with your own reality. Don't pursue perfection, adjust as the business evolves. "Taobao Technology These 10 Years".

Technology selection

  1. Comparison of Spring Cloud and dubbo components

    dubbo:zookeeper+dubbo+springmvc/springboot
    通信方式:rpc
    注册中心:zookeeper,nacos
    配置中心:diamond(淘宝开发)
    
    spring cloud:spring+Netflix
    通信方式:http restful
    注册中心:eureka,consul,nacos				
    配置中心:config
    断路器:hystrix
    网关:zuul,gateway
    分布式追踪系统:sleuth+zipkin
    
    
  2. difference

    dubbo spring cloud
    background Great domestic influence Great influence abroad Tie
    Community activity Low (it's good again) high cloud wins
    Architectural integrity Imperfect (some dubbo does not provide and requires a third party, it only focuses on service governance) It is relatively complete and has everything you need for microservice components. cloud wins
    Learning cost dubbo needs supporting learning Seamless spring cloud wins
    performance high. (Based on Netty) low. (Based on http, it must be created every time). This loss of performance is acceptable for most applications. The HTTP style API is very convenient. Convenience is exchanged for a small performance loss. dubbo wins

Spring Cloud

concept

Spring Cloud is an organic collection of a series of frameworks that implement microservice architecture.

It is a tool set built on the basis of Spring Boot to simplify the construction of distributed systems. It is a collection of projects with many sub-projects. Using Spring Boot's development convenience, the development of distributed system infrastructure (service registration and discovery, fuse mechanism, gateway routing, configuration center, message bus, load balancing, link tracking, etc.) is ingeniously simplified.

Version evolution

  1. Version process: version name. version number.

  2. Version name: Alphabetical order of the London Underground.

  3. Version number: M (milestone): milestone,

    ​ SR (Service Releases): stable version,

    ​ RC (Release Candidate): The candidate version of the stable version, which is the last version of the stable version.

看官网:查询每个cloud版本下面的子模块的版本。
https://spring.io/projects/spring-cloud
此网页的最下面,目前最新的SpringCloud最新版本是:Greenwich.SR2
版本记录
https://github.com/spring-cloud/spring-cloud-release/releases

Overall structure

composition:

  1. Service registration and discovery components: Eureka, Zookeeper, Consul, Nacos, etc. Eureka is based on REST style.

  2. Service call components: Hystrix (fuse degradation, in the event of a dependent service failure, by isolating the system dependent service to prevent service cascading failure, and providing a failure rollback mechanism to enable the system to recover from the exception faster) , Ribbon (client load balancing, used to provide client-side software load balancing algorithms, providing a series of complete configuration items: connection timeout, retry, etc.), OpenFeign (elegant encapsulation of Ribbon, is a declarative RESTful network request client It makes it easier and faster to write Web service clients).

  3. Gateway: routing and filtering. Zuul, Gateway.

  4. Configuration Center: Provides the functions of centralized configuration management and dynamic refresh configuration; the configuration is stored through Git or other methods.

  5. Message components: Spring Cloud Stream (abstract distributed messages, including publishing and subscribing, packet consumption, etc., to achieve asynchronous communication between microservices) and Spring Cloud Bus (mainly providing event communication between services, such as refreshing configuration)

  6. Security control component: Based on the OAuth2.0 open network security standard, Spring Cloud Security provides functions such as single sign-on, resource authorization, and token management.

  7. Link tracking components: Spring Cloud Sleuth (collect data on the call link), Zipkin (store, count, and display the information collected by Sleuth).

    The content of each point will be discussed later.

Independent microservice writing

development tools

STS / IDEA

https://spring.io/tools

purpose

Look at the effect of eureka registry through this service.

Review Spring Boot.

Reduce a lot of configuration. Rapid development.

Use Starter to integrate a new framework. Such as redis, web, etc. Add dependencies, add configuration files.

Embedded server makes development and deployment convenient.

Spring Boot介绍:
https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/

Guess you like

Origin blog.csdn.net/qq_38238041/article/details/106737681