索引:SpringCloudAlibaba分布式组件全部框架笔记
- 一·推荐一套分布式微服务的版本管理父工程pom模板:Springcloud、SpringCloudAlibaba、Springboot
- 二·SpringBoot、SpringCloud、SpringCloudAlibaba等各种组件的版本匹配图:
- [三·SpringBoot 3.x.x版本项目中,必须在pom中引入一个插件,否则接口方法参数无法解析](#三·SpringBoot 3.x.x版本项目中,必须在pom中引入一个插件,否则接口方法参数无法解析)
- [四·Spring Cloud Alibaba 参考文档:](#四·Spring Cloud Alibaba 参考文档:)
- 五·Nacos:服务注册发现、配置管理中心
- 六·LoadBalancer:远程服务调用框架、客户端负载均衡工具
- 七·Openfeign(推荐):远程服务调用框架、客户端负载均衡工具
- 八·Gateway:微服务端网关路由
- 九·Sentinel:服务流量治理组件
- 十·Seata:分布式事务组件
-
- 1.官方文档:
- 2.Seata各大模式原理分析:
- [3.Seata2.0 安装部署,与Nacos、SpringCloud项目集成笔记:](#3.Seata2.0 安装部署,与Nacos、SpringCloud项目集成笔记:)
- 十一·Micrometer:微服务接口调用链路追踪组件
-
- 1.Micrometer安装使用详解:
- [2.SpringBoot 使用 Micrometer 集成 Prometheus 监控 Java 应用性能](#2.SpringBoot 使用 Micrometer 集成 Prometheus 监控 Java 应用性能)
一·推荐一套分布式微服务的版本管理父工程pom模板:Springcloud、SpringCloudAlibaba、Springboot
xml
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hutool.version>5.8.22</hutool.version>
<lombok.version>1.18.26</lombok.version>
<druid.version>1.1.20</druid.version>
<mybatis.springboot.version>3.0.2</mybatis.springboot.version>
<mybatisPlus.springboot.version>3.5.7</mybatisPlus.springboot.version>
<mysql.version>8.0.11</mysql.version>
<swagger3.version>2.2.0</swagger3.version>
<mapper.version>4.2.3</mapper.version>
<fastjson2.version>2.0.40</fastjson2.version>
<persistence-api.version>1.0.2</persistence-api.version>
<spring.boot.test.version>3.1.5</spring.boot.test.version>
<spring.boot.version>3.3.0</spring.boot.version>
<spring.cloud.version>2023.0.2</spring.cloud.version>
<spring.cloud.alibaba.version>2023.0.1.0</spring.cloud.alibaba.version>
</properties>
<dependencyManagement>
<dependencies>
<!--springboot 版本控制依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--springcloud 版本控制依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--springcloud alibaba 版本控制依赖-->
<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>
<!-- <!–SpringBoot集成mybatis–>-->
<!-- <dependency>-->
<!-- <groupId>org.mybatis.spring.boot</groupId>-->
<!-- <artifactId>mybatis-spring-boot-starter</artifactId>-->
<!-- <version>${mybatis.springboot.version}</version>-->
<!-- </dependency>-->
<!--SpringBoot集成mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>${mybatisPlus.springboot.version}</version>
</dependency>
<!--Mysql数据库驱动8 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--SpringBoot集成druid连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!--通用Mapper4之tk.mybatis-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
<!--persistence-->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence-api.version}</version>
</dependency>
<!-- fastjson2 -->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>${fastjson2.version}</version>
</dependency>
<!-- swagger3 调用方式 http://你的主机IP地址:5555/swagger-ui/index.html -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${swagger3.version}</version>
</dependency>
<!--hutool-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<!-- spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.test.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lmf.cloud</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<!-- Springboot3升级之后必须添加的maven编译插件,这样才能解析接口方法参数,默认是不能自动解析接口参数-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<parameters>true</parameters>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
二·SpringBoot、SpringCloud、SpringCloudAlibaba等各种组件的版本匹配图:
三·SpringBoot 3.x.x版本项目中,必须在pom中引入一个插件,否则接口方法参数无法解析
xml
<build>
<plugins>
<!-- Springboot3升级之后必须添加的maven编译插件,这样才能解析接口方法参数,默认是不能自动解析接口参数-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<parameters>true</parameters>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
四·Spring Cloud Alibaba 参考文档:
1.尚硅谷学习笔记脑图下载:2024版
https://gitee.com/lmf-2021/SpringCloud2024/blob/master/SpringCloud第3季2024.html
2.官方全套示例文档,比较简短,不适合新手,适合熟手复习
https://spring-cloud-alibaba-group.github.io/github-pages/2022/zh-cn/
五·Nacos:服务注册发现、配置管理中心
服务注册发现、配置管理中心;本身就是一个单独的微服务;同时也是所有分布式微服务组件的基础应用
xml
<!-- Springcloud-nacos-服务注册中心整合依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- springcloud-nacos-config-配置中心整合依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--Springcloud-bootstrap容器整合依赖,可以使用bootstrap.yml配置文件-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
1.Nacos分阶段引入示例:
https://www.cnblogs.com/crazymakercircle/p/14231815.html
2.Nacos配置yml完整示例与解释:
https://developer.aliyun.com/article/1157617
补充1:Nacos服务跨分组调用
https://blog.csdn.net/m0_56287495/article/details/129240577
六·LoadBalancer:远程服务调用框架、客户端负载均衡工具
远程服务调用框架、客户端负载均衡工具(Nginx是服务端负载均衡工具);需要依赖服务注册与发现;支持与多种http库集成
xml
<!-- Springcloud-loadbalancer-远程服务调用、负载均衡整合依赖,可以单独使用-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
https://www.cnblogs.com/itxiaoshen/p/16247702.html
七·Openfeign(推荐):远程服务调用框架、客户端负载均衡工具
远程服务调用框架、客户端负载均衡工具(Nginx是服务端负载均衡工具);需要依赖服务注册与发现,内部整合了LoadBalancer负载均衡,可以完全替代LoadBalancer组件
xml
<!--Springcloud-openfeign-远程服务调用、负载均衡整合依赖,底层整合loadbalancer,因此需要该依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- Springcloud-loadbalancer-远程服务调用、负载均衡整合依赖,可以单独使用-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- 根据需要是否添加下面依赖,用于替换Openfeign底层的http请求为请求连接池-->
<!-- httpclient5-->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<!-- feign-hc5-整合依赖-->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-hc5</artifactId>
</dependency>
https://blog.csdn.net/weixin_44606481/article/details/132499972
补充1:Openfeign各种属性配置官方文档
https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/appendix.html
八·Gateway:微服务端网关路由
微服务端网关路由;本身就是一个单独的微服务;需要依赖服务注册与发现;Gateway服务配置路由之后,再访问Gateway服务,Gateway服务就可以把请求转发到其他具体微服务上面;
xml
<!-- 网关是响应式编程,必须删除掉 spring-boot-starter-web 场景dependency-->
<!-- Springcloud-gateway-网关路由整合依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- 根据需要添加:解决netty框架与mac系统m1芯片集成dns问题-->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<!-- <version>4.1.75.Final</version> <!–版本号自己切–>-->
<classifier>osx-aarch_64</classifier>
</dependency>
1.入门概括介绍:
https://developer.aliyun.com/article/1294775#slide-4
2.详细介绍:
https://www.cnblogs.com/crazymakercircle/p/11704077.html#autoid-h2-0-0-0
3.官方中文文档-最新版:
https://springdoc.cn/spring-cloud-gateway/#setrequestheader
补充1:Nginx网关与Gateway网关区分:
一般情况:将Nginx设置为流量网关,Gateway设置为业务网关,两者作用都是负载均衡作用,Gateway网关细腻度更低
https://developer.aliyun.com/article/1392682
https://developer.aliyun.com/article/1002990#slide-3
九·Sentinel:服务流量治理组件
服务流量治理组件;本身就是一个单独的微服务;A微服务配置注册到Sentinel服务之后,访问A微服务接口,请求的流量就会被Sentinel服务监控到
xml
<!-- SpringCloud alibaba sentinel 服务流量治理组件-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
1.官方文档:
https://sentinelguard.io/zh-cn/docs/basic-implementation.html
2.详细笔记:
https://www.cnblogs.com/crazymakercircle/p/14285001.html#autoid-h2-0-0-0
3.整合实战笔记:
https://www.cnblogs.com/crazytrip/p/15212602.html
4.尚硅谷的Springcloud第3季脑图:下载本地查看
https://gitee.com/lmf-2021/SpringCloud2024/blob/master/SpringCloud第3季2024.html
十·Seata:分布式事务组件
分布式事务组件;本身就是一个单独的微服务;需要依赖服务注册与发现
xml
<!-- Springcloud-seata-分布式事务整合依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
1.官方文档:
https://seata.apache.org/zh-cn/docs/overview/what-is-seata
2.Seata各大模式原理分析:
https://blog.csdn.net/qq_48721706/article/details/122656490
3.Seata2.0 安装部署,与Nacos、SpringCloud项目集成笔记:
(推荐)https://blog.csdn.net/weixin_43840661/article/details/135432796
https://blog.csdn.net/weixin_36027342/article/details/135897943
https://blog.csdn.net/qq_42767920/article/details/135743126
十一·Micrometer:微服务接口调用链路追踪组件
xml
<!--micrometer-tracing-bom导入链路追踪版本中心 1-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bom</artifactId>
<version>${micrometer-tracing.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--micrometer-tracing指标追踪 2-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
<version>${micrometer-tracing.version}</version>
</dependency>
<!--micrometer-tracing-bridge-brave适配zipkin的桥接包 3-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
<version>${micrometer-tracing.version}</version>
</dependency>
<!--micrometer-observation 4-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
<version>${micrometer-observation.version}</version>
</dependency>
<!--feign-micrometer 5-->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-micrometer</artifactId>
<version>${feign-micrometer.version}</version>
</dependency>
<!--zipkin-reporter-brave 6-->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
<version>${zipkin-reporter-brave.version}</version>
</dependency>
1.Micrometer安装使用详解:
https://www.cnblogs.com/cjsblog/p/11556029.html
2.SpringBoot 使用 Micrometer 集成 Prometheus 监控 Java 应用性能
https://blog.csdn.net/aixiaoyang168/article/details/100866159
https://juejin.cn/post/7051109463180181535