一、SpringCloud简介
springcloud官方文档(Hoxton SR5)
springcloud中文文档
1、服务治理
服务治理就是进行服务的自动化管理,其核心是服务的自动注册与发现。
- 服务注册:服务实例将自身服务信息注册到注册中心
- 服务发现:服务实例通过注册中心,获取到注册到其中的服务实例的信息,通过这些信息去请求它们提供的服务。
- 服务剔除:服务注册中心将出问题的服务自动剔除到可用列表之外,使其不会被调用到。
2、服务调用
多个服务之间的远程调用,目前主流的远程调用技术有基于HTTP的RESTful接口以及基于TCP的RPC协议。
3、服务网关
API网关直面意思是将所有API调用统一接入到API网关层,由网关层统一接入和输出。
一个网关的基本功能有:统一接入、安全防护、协议适配、流量管控、长短链接支持、容错能力。4、服务容错
在微服务当中,一个请求经常会涉及到调用几个服务,如果其中某个服务不可用,没有做服务容错的话,极有可能会造成一连串的服务不可用,这就是雪崩效应。
我们没法预防雪崩效应的发生,只能尽可能去做好容错。服务容错的三个核心思想是:
- 不被外界环境影响
- 不被上游请求压垮
- 不被下游响应拖垮
5、链路追踪
一次请求往往需要涉及到多个服务,因此需要对一次请求涉及的多个服务链路进行日志记录,性能监控即链路追踪。
二、Spring Cloud Alibaba
1、简介
Spring官网:https://spring.io/projects/spring-cloud-alibaba
GitHub:https://github.com/alibaba/spring-cloud-alibaba
GitHub中文文档:https://github.com/alibaba/spring-cloud-alibaba/blob/master/README-zh.md
版本说明:https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明
阿里云脚手架构建项目:https://start.aliyun.com/bootstrap.html
版本说明
| Spring Cloud Alibaba Version | Spring Cloud Version | Spring Boot Version |
|---|---|---|
| 2021.0.4.0* | Spring Cloud 2021.0.4 | 2.6.11 |
| 2021.0.1.0 | Spring Cloud 2021.0.1 | 2.6.3 |
| 2021.1 | Spring Cloud 2020.0.1 | 2.4.2 |
组件版本关系
| Spring Cloud Alibaba Version | Sentinel Version | Nacos Version | RocketMQ Version | Dubbo Version | Seata Version |
|---|---|---|---|---|---|
| 2.2.10-RC1 | 1.8.6 | 2.2.0 | 4.9.4 | ~ | 1.6.1 |
| 2022.0.0.0-RC1 | 1.8.6 | 2.2.1-RC | 4.9.4 | ~ | 1.6.1 |
| 2.2.9.RELEASE | 1.8.5 | 2.1.0 | 4.9.4 | ~ | 1.5.2 |
| 2021.0.4.0 | 1.8.5 | 2.0.4 | 4.9.4 | ~ | 1.5.2 |
| 2.2.8.RELEASE | 1.8.4 | 2.1.0 | 4.9.3 | ~ | 1.5.1 |
| 2021.0.1.0 | 1.8.3 | 1.4.2 | 4.9.2 | ~ | 1.4.2 |
| 2.2.7.RELEASE | 1.8.1 | 2.0.3 | 4.6.1 | 2.7.13 | 1.3.0 |
| 2.2.6.RELEASE | 1.8.1 | 1.4.2 | 4.4.0 | 2.7.8 | 1.3.0 |
2、搭建框架
利用阿里云脚手架构建项目:https://start.aliyun.com/bootstrap.html,进行搭建。
这里选择SpringBoot版本为:2.6.11,对应的SpringCloudAlibaba版本为2021.0.4.0
版本说明:https://spring-cloud-alibaba-group.github.io/github-pages/2021/zh-cn/index.html
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.11</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><spring-cloud-alibaba.version>2021.0.4.0</spring-cloud-alibaba.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring-cloud-alibaba.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
