SpringCloud 入门
系列链接:
- GitHub:源码
- SpringCloud(1)–入门、版本、环境搭建
- SpringCloud(2)–服务注册与发现(Eureka、Zookeeper、Consul)
- SpringCloud(3)–服务调用(Ribbon、OpenFeign)
- SpringCloud(4)–服务降级(Hystrix、降级、熔断、监控)
- SpringCloud(5)–服务网关(GateWay)
- …
版本的选择
查看SpringCloud和SpringBoot之间版本的依赖关系:
- https://spring.io/projects/spring-cloud#overview
- https://start.spring.io/actuator/info,返回详细json信息
部分组件停用
首先连接下各个组件:
-
服务注册中心:EUREKA
-
服务负载均衡与调用:NETFLIX OSS RIBBON
-
服务负载与调用:NETTFLIX
-
服务熔断降级:HYSTRIX
-
服务网关:Zuul
-
服务分布式配置:SpringCloud Config
-
服务开发:SpingBoot
SpringCloud升级后,部分组件停用:
- Eureka 停用,可以使用 Zookeeper 作为服务注册中心
- 服务调用,Ribbon 准备停更,代替为 LoadBalance
- Feign 改为 OpenFeign
- Hystrix 停更,改为 resilence4j 或者阿里巴巴的 sentienl
- Zuul 改为 gateway
- 服务配置 Config 改为 Nacos
- 服务总线 Bus 改为 Nacos
环境搭建
接下来我们会搭建一个订单-支付模块微服务。
父工程创建
父工程依赖
<groupId>com.moke.springcloud</groupId>
<artifactId>cloud1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<!--统一管理jar包和版本-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.version>4.12</junit.version>
<log4j.version>1.2.17</log4j.version>
<lombok.version>1.16.18</lombok.version>
<mysql.version>8.0.18</mysql.version>
<druid.verison>1.1.16</druid.verison>
<mybatis.spring.boot.verison>1.3.0</mybatis.spring.boot.verison>
</properties>
<!--子模块继承之后,提供作用:锁定版本+子module不用谢groupId和version-->
<dependencyManagement>
<dependencies>
<!--spring boot 2.2.2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud Hoxton.SR1-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud alibaba 2.1.0.RELEASE-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- MySql -->
<dependency>