Skip to content

Commit 220f1b5

Browse files
committed
Add lesson 15
1 parent bb12e8f commit 220f1b5

File tree

56 files changed

+2452
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2452
-1
lines changed

spring-cloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Spring Cloud 系列课程致力于以实战的方式覆盖 Spring Cloud 的功
195195
* 本章小结(10分钟)
196196
* 问答互动(20分钟)
197197

198-
### 第十五节 分布式应用跟踪
198+
### [第十五节 分布式应用跟踪](https://segmentfault.com/l/1500000011386721/play) ([课件]((https://github.com/mercyblitz/segmentfault-lessons/tree/master/spring-cloud/lesson-14))) [[问答](https://segmentfault.com/l/1500000011386721/d/1560000012512486)]
199199

200200
* 受众群体:具备一定的`Java`服务端编程经验更佳
201201

spring-cloud/lesson-15/Dapper.pdf

1.48 MB
Binary file not shown.

spring-cloud/lesson-15/README.md

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
# [Spring Cloud 分布式应用跟踪](https://segmentfault.com/l/1500000011386721)
2+
3+
4+
5+
6+
7+
SpanID : 阶段性 ID,比如一次 RPC 有可能多 Span
8+
9+
10+
11+
TraceID:一次 RPC 只有一个 TraceID
12+
13+
14+
15+
16+
17+
## 整合 Spring Cloud Sleuth
18+
19+
20+
21+
### 增加依赖
22+
23+
```xml
24+
<!-- 整合 Spring Cloud Sleuth -->
25+
<dependency>
26+
<groupId>org.springframework.cloud</groupId>
27+
<artifactId>spring-cloud-starter-sleuth</artifactId>
28+
</dependency>
29+
```
30+
31+
32+
33+
34+
35+
## Zipkin 整合
36+
37+
38+
39+
### 新增 Zipkin 服务器
40+
41+
42+
43+
#### 增加 Maven 依赖
44+
45+
46+
47+
```xml
48+
<!-- Zipkin Server 整合 -->
49+
<dependency>
50+
<groupId>io.zipkin.java</groupId>
51+
<artifactId>zipkin-server</artifactId>
52+
</dependency>
53+
54+
<!-- Zipkin Server UI 整合 -->
55+
<dependency>
56+
<groupId>io.zipkin.java</groupId>
57+
<artifactId>zipkin-autoconfigure-ui</artifactId>
58+
</dependency>
59+
```
60+
61+
62+
63+
#### 激活 Zipkin 服务器
64+
65+
66+
67+
HTTP 方式采集
68+
69+
```java
70+
package com.segumentfault.spring.cloud.lesson15;
71+
72+
import org.springframework.boot.SpringApplication;
73+
import org.springframework.boot.autoconfigure.SpringBootApplication;
74+
import zipkin.server.EnableZipkinServer;
75+
76+
/**
77+
* Zipkin 服务器应用
78+
*
79+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
80+
* @since 0.0.1
81+
*/
82+
@SpringBootApplication
83+
@EnableZipkinServer
84+
public class ZipkinServerApplication {
85+
86+
public static void main(String[] args) {
87+
SpringApplication.run(ZipkinServerApplication.class, args);
88+
}
89+
}
90+
```
91+
92+
93+
94+
#### 配置 Zipkin 服务器
95+
96+
```properties
97+
## 应用元信息
98+
## Zipkin 服务器应用名称
99+
spring.application.name = zipkin-server
100+
101+
## Zipkin 服务器服务端口
102+
server.port = 20000
103+
104+
## 管理端口安全失效
105+
management.security.enabled = false
106+
```
107+
108+
109+
110+
### 整合 ZipKin 客户端
111+
112+
113+
114+
#### 改造 `user-service-client`
115+
116+
117+
118+
HTTP 方式上报
119+
120+
121+
122+
##### 增加 Maven 依赖
123+
124+
```xml
125+
<!-- 整合 Spring Cloud Zipkin -->
126+
<dependency>
127+
<groupId>org.springframework.cloud</groupId>
128+
<artifactId>spring-cloud-starter-zipkin</artifactId>
129+
</dependency>
130+
```
131+
132+
133+
134+
135+
136+
##### 配置:连接 zipkin 服务器
137+
138+
```properties
139+
## Zipkin 配置
140+
### 配置 Zipkin 服务器
141+
zipkin.server.host = localhost
142+
zipkin.server.port = 20000
143+
spring.zipkin.base-url = http://${zipkin.server.host}:${zipkin.server.port}
144+
```
145+
146+
147+
148+
#### 改造 `user-service-provider`
149+
150+
151+
152+
##### 增加 Maven 依赖
153+
154+
```xml
155+
<!-- 整合 Spring Cloud Zipkin -->
156+
<dependency>
157+
<groupId>org.springframework.cloud</groupId>
158+
<artifactId>spring-cloud-starter-zipkin</artifactId>
159+
</dependency>
160+
```
161+
162+
163+
164+
165+
166+
##### 配置:连接 zipkin 服务器
167+
168+
```properties
169+
## Zipkin 配置
170+
### 配置 Zipkin 服务器
171+
zipkin.server.host = localhost
172+
zipkin.server.port = 20000
173+
spring.zipkin.base-url = http://${zipkin.server.host}:${zipkin.server.port}
174+
```
175+
176+
177+
178+
### 改造Zipkin 服务器:使用 Stream 方式订阅
179+
180+
181+
182+
#### 增加 Maven 依赖
183+
184+
```xml
185+
<!-- zipkin 整合 Spring Cloud Sleuth Stream -->
186+
<dependency>
187+
<groupId>org.springframework.cloud</groupId>
188+
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
189+
</dependency>
190+
191+
<!-- 整合 Spring Cloud Stream Binder Rabbit MQ -->
192+
<dependency>
193+
<groupId>org.springframework.cloud</groupId>
194+
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
195+
</dependency>
196+
```
197+
198+
199+
200+
#### 替换激活注解:`@EnableZipkinStreamServer`
201+
202+
203+
204+
Stream 方式采集
205+
206+
```java
207+
package com.segumentfault.spring.cloud.lesson15.zipkin.server;
208+
209+
import org.springframework.boot.SpringApplication;
210+
import org.springframework.boot.autoconfigure.SpringBootApplication;
211+
import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer;
212+
213+
/**
214+
* Zipkin 服务器应用
215+
*
216+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
217+
* @since 0.0.1
218+
*/
219+
@SpringBootApplication
220+
//@EnableZipkinServer
221+
@EnableZipkinStreamServer
222+
public class ZipkinServerApplication {
223+
224+
public static void main(String[] args) {
225+
SpringApplication.run(ZipkinServerApplication.class, args);
226+
}
227+
}
228+
```
229+
230+
231+
232+
233+
234+
### 改造 `user-service-client`
235+
236+
237+
238+
#### 增加 Maven 依赖
239+
240+
Stream 方式上报
241+
242+
```xml
243+
<!-- 整合 Spring Cloud Sleuth -->
244+
<dependency>
245+
<groupId>org.springframework.cloud</groupId>
246+
<artifactId>spring-cloud-starter-sleuth</artifactId>
247+
</dependency>
248+
<!-- 整合 Spring Cloud Sleuth Stream -->
249+
<dependency>
250+
<groupId>org.springframework.cloud</groupId>
251+
<artifactId>spring-cloud-sleuth-stream</artifactId>
252+
</dependency>
253+
<!-- 整合 Spring Cloud Stream Binder Rabbit MQ -->
254+
<dependency>
255+
<groupId>org.springframework.cloud</groupId>
256+
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
257+
</dependency>
258+
```
259+
260+
261+
262+
> 注意应移除 `spring-cloud-starter-zipkin` 依赖
263+
264+
265+
266+
### 改造 `user-service-provider`
267+
268+
269+
270+
#### 增加 Maven 依赖
271+
272+
Stream 方式上报
273+
274+
```xml
275+
<!-- 整合 Spring Cloud Sleuth -->
276+
<dependency>
277+
<groupId>org.springframework.cloud</groupId>
278+
<artifactId>spring-cloud-starter-sleuth</artifactId>
279+
</dependency>
280+
<!-- 整合 Spring Cloud Sleuth Stream -->
281+
<dependency>
282+
<groupId>org.springframework.cloud</groupId>
283+
<artifactId>spring-cloud-sleuth-stream</artifactId>
284+
</dependency>
285+
<!-- 整合 Spring Cloud Stream Binder Rabbit MQ -->
286+
<dependency>
287+
<groupId>org.springframework.cloud</groupId>
288+
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
289+
</dependency>
290+
```
291+
292+
293+
294+
> 注意应移除 `spring-cloud-starter-zipkin` 依赖
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-cloud-lesson-15</artifactId>
7+
<groupId>com.segumentfault</groupId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>config-server</artifactId>
13+
14+
<dependencies>
15+
16+
<!-- 依赖 Spring Cloud Config Server -->
17+
<dependency>
18+
<groupId>org.springframework.cloud</groupId>
19+
<artifactId>spring-cloud-config-server</artifactId>
20+
</dependency>
21+
22+
<!-- 依赖 Spring Cloud Netflix Eureka -->
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-starter-eureka</artifactId>
26+
</dependency>
27+
28+
</dependencies>
29+
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.segumentfault.spring.cloud.lesson15.config.server;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
import org.springframework.cloud.config.server.EnableConfigServer;
7+
8+
/**
9+
* 配置服务器应用
10+
*
11+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
12+
* @since 1.0.0
13+
*/
14+
@EnableConfigServer
15+
@EnableDiscoveryClient
16+
@SpringBootApplication
17+
public class ConfigServerApplication {
18+
19+
public static void main(String[] args) {
20+
SpringApplication.run(ConfigServerApplication.class, args);
21+
}
22+
}

0 commit comments

Comments
 (0)