为什么写?

时下Spring Cloud Netflix全家桶已经成为了事实上的微服务实践落地的不二选择,笔者在公司也负责、参与一系列的微服务改造项目,该系列文章涵盖了笔者从刚接触该技术栈的入门到实战,再到源码分析的整个过程,是对自己经历的一次梳理,希望对您也有所帮助。

准备写哪些内容?

主要针对Spring Cloud Netflix主要技术栈,包括:

  • 服务注册发现Eureka
  • 负载均衡 Ribbon
  • 声明式接口调用 Feign
  • 资源隔离、限流、熔断、降级 Hystrix
  • 网关 Zuul

预计会按照此顺序进行撰写,每个技术点会从解决了什么问题、入门Demo、核心功能实战、核心机制源码剖析几个方面描述。

Spring Cloud基本常识

如何找到指定时间发布的SpringCloud版本?

去maven仓库找到对应的版本号
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies

如何找到与之兼容的SpringBoot版本?

  1. Google搜索Spring Cloud ${版本名称} RELEASE 即可找到对应的发布页面,比如本次我们使用的就是刚发布的最新版HOXTON
    https://spring.io/blog/2019/11/28/spring-cloud-hoxton-released

  2. 然后注意 第二个标题 Notable Changes in the xxxxx Train,就可以找到对应的SpringBoot版本了。
    Spring Cloud Hoxton.RELEASE is based on Spring Boot 2.2.1.RELEASE.

通用SpringCloud工程Maven配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>与SpringCloud兼容的SpringBoot版本</version>
</parent>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<spring.cloud-version>SpringCloud版本号</spring.cloud-version>
</properties>

<!-- 你的依赖 -->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Comments