SpringCloudAlibaba隨筆目錄
二、SpringCloudAlibaba項目之Nacos搭建及服務注冊
三、SpringCloudAlibaba項目之生產者與消費者
四、SpringCloudAlibaba項目之Ribbon負載均衡
五、SpringCloudAlibaba項目之OpenFeign遠程調用
六、SpringCloudAlibaba項目之Nacos-config配置中心
七、SpringCloudAlibaba項目之Sentinel流量控制
八、SpringCloudAlibaba項目之Seata分布式事務
九、SpringCloudAlibaba項目之GateWay網關
十、SpringCloudAlibaba項目之SkyWalking鏈路追蹤
SpringCloudAlibaba項目父工程搭建
1、微服務
2、SpringCloud介紹
Spring Cloud是一系列框架的有序集合。它利用Spring Boot的開發便利性巧妙地簡化了分布式系統基礎設施的開發,如服務發現注冊、配置中心、消息總線、負載均衡、斷路器、數據監控等,都可以用Spring Boot的開發風格做到一鍵啟動和部署。Spring Cloud並沒有重復制造輪子,它只是將各家公司開發的比較成熟、經得起實際考驗的服務框架組合起來,通過Spring Boot風格進行再封裝屏蔽掉了復雜的配置和實現原理,最終給開發者留出了一套簡單易懂、易部署和易維護的分布式系統開發工具包。
3、SpringCloudAlibaba
很多人可能會問,有了spring cloud這個微服務的框架,為什么又要使用spring cloud alibaba這個框架了?最重要的原因在於spring cloud中的幾乎所有的組件都使用Netflix公司的產品,然后在其基礎上做了一層封裝。然而Netflix的服務發現組件Eureka已經停止更新,我們公司在使用的時候就發現過其一個細小的Bug;而其他的眾多組件預計會在明年(即2020年)停止維護。所以急需其他的一些替代產品,也就是spring cloud alibaba,目前正處於蓬勃發展的態式。
Spring Cloud Alibaba是Spring Cloud下的一個子項目,Spring Cloud Alibaba為分布式應用程序開發提供了一站式解決方案,它包含開發分布式應用程序所需的所有組件,使您可以輕松地使用Spring Cloud開發應用程序,使用Spring Cloud Alibaba,您只需要添加一些注解和少量配置即可將Spring Cloud應用程序連接到Alibaba的分布式解決方案,並使用Alibaba中間件構建分布式應用程序系統。Spring Cloud Alibaba 是阿里巴巴開源中間件跟 Spring Cloud 體系的融合。
官方鏈接
官方自述:https://github.com/alibaba/spring-cloud-alibaba/blob/master/README-zh.md
官方github:https://github.com/alibaba/spring-cloud-alibaba
官方Samples:https://github.com/alibaba/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples
版本兼容
我們需要關注的緊緊是版本兼容問題
SpringCloud和SpringBoot的版本兼容:
https://spring.io/projects/spring-cloud
SpringCloudAlibaba和SpringBoot的版本兼容:
https://github.com/alibaba/spring-cloud-alibaba/blob/master/README-zh.md
SpringCloudAlibaba官方整理的版本說明:
https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
Spring Cloud Version | Spring Cloud Alibaba Version | Spring Boot Version |
---|---|---|
Spring Cloud 2020.0.1 |
2021.1 |
2.4.2 |
Spring Cloud Hoxton.SR12 |
2.2.7.RELEASE |
2.3.12.RELEASE |
Spring Cloud Hoxton.SR9 |
2.2.6.RELEASE |
2.3.2.RELEASE |
Spring Cloud Greenwich.SR6 |
2.1.4.RELEASE |
2.1.13.RELEASE |
Spring Cloud Hoxton.SR3 |
2.2.1.RELEASE |
2.2.5.RELEASE |
Spring Cloud Hoxton.RELEASE |
2.2.0.RELEASE |
2.2.X.RELEASE |
Spring Cloud Greenwich |
2.1.2.RELEASE |
2.1.X.RELEASE |
Spring Cloud Finchley |
2.0.4.RELEASE(停止維護,建議升級) |
2.0.X.RELEASE |
Spring Cloud Edgware |
1.5.1.RELEASE(停止維護,建議升級) |
1.5.X.RELEASE |
組件版本關系:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
Spring Cloud Alibaba Version | Sentinel Version | Nacos Version | RocketMQ Version | Dubbo Version | Seata Version |
---|---|---|---|---|---|
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 |
2021.1 or 2.2.5.RELEASE or 2.1.4.RELEASE or 2.0.4.RELEASE |
1.8.0 |
1.4.1 |
4.4.0 |
2.7.8 |
1.3.0 |
2.2.3.RELEASE or 2.1.3.RELEASE or 2.0.3.RELEASE |
1.8.0 |
1.3.3 |
4.4.0 |
2.7.8 |
1.3.0 |
2.2.1.RELEASE or 2.1.2.RELEASE or 2.0.2.RELEASE |
1.7.1 |
1.2.1 |
4.4.0 |
2.7.6 |
1.2.0 |
2.2.0.RELEASE |
1.7.1 |
1.1.4 |
4.4.0 |
2.7.4.1 |
1.0.0 |
2.1.1.RELEASE or 2.0.1.RELEASE or 1.5.1.RELEASE |
1.7.0 |
1.1.4 |
4.4.0 |
2.7.3 |
0.9.0 |
2.1.0.RELEASE or 2.0.0.RELEASE or 1.5.0.RELEASE |
1.6.3 |
1.1.1 |
4.4.0 |
2.7.3 |
0.7.1 |
這里我們使用的版本:
Spring Cloud Version:Hoxton.SR12
Spring Cloud Alibaba Version:2.2.7.RELEASE
Spring Boot Version:2.3.12.RELEASE
4、快速搭建
准備
開發工具:IntelliJ IDEA 2018.3.2 x64
java:jdk1.8
Maven:apache-maven-3.6.1
要求
熟悉springboot
構建父工程,整個項目是由maven
進行管理,這里使用默認的初始化服務地址,不然后面選擇Maven POM創建項目時會出問題。
父工程目錄:
修改pom文件
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.qt</groupId> <artifactId>spring-cloud-alibaba</artifactId> <version>1.0-SNAPSHOT</version> <properties> <!-- java版本 --> <java.version>1.8</java.version> <!-- SpringBoot版本 --> <spring.boot.version>2.3.12.RELEASE</spring.boot.version> <!-- Spring Cloud Alibaba 版本 --> <spring.cloud.alibaba>2.2.7.RELEASE</spring.cloud.alibaba> <!-- Spring Cloud 版本 --> <spring.cloud>Hoxton.SR12</spring.cloud> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <dependencies> <!-- SpringBoot基本場景啟動依賴 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- SpringBoot測試類依賴 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!-- 版本依賴管理器 --> <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> <!-- Spring Cloud Alibaba 版本管理器 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring.cloud.alibaba}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Spring Cloud 版本管理器 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring.cloud}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
此時父工程就搭建完成了,就是這么簡單。
整個項目是由maven
進行管理的, 依賴包就是我們開發時需要用到的第三方jar包, 也就是框架, 這里為什么什么也不選, 因為我們要做的是微服務, 所以框架結構為一個基座
+多個子模塊
, 我們上面建立的父工程就是基座
, 你可以把它當成一個工作空間
用途是管理子模塊。
最近在項目結束之余,自學了一下微服務,自主搭建springcloud項目,特此留作筆記,,,