├── README.md
├── trace1-stream
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── primeton
│ │ └── trace1_stream
│ │ └── Trace1Application.java
│ └── resources
│ ├── application.yml
│ └── bootstrap.yml
├── trace1
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── primeton
│ │ └── trace1
│ │ └── Trace1Application.java
│ └── resources
│ ├── application.yml
│ └── bootstrap.yml
├── trace2-stream
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── primeton
│ │ └── trace2_stream
│ │ └── Trace2Application.java
│ └── resources
│ ├── application.yml
│ └── bootstrap.yml
├── trace2
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── primeton
│ │ └── trace2
│ │ └── Trace2Application.java
│ └── resources
│ ├── application.yml
│ └── bootstrap.yml
├── zipkinserver-stream
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── primeton
│ │ └── zipkinserver_stream
│ │ └── ZipkinApplication.java
│ └── resources
│ └── application.yml
└── zipkinserver
├── pom.xml
└── src
└── main
├── java
└── com
│ └── primeton
│ └── zipkinserver
│ └── ZipkinApplication.java
└── resources
└── application.yml
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 随着分布式服务架构的流行,特别是微服务等设计理念在系统中的应用,系统规模也会变得越来越大,各微服务间的调用关系也变得越来越复杂。通常一个由客户端发起的请求在后端系统中会经过多个不同的微服务调用来协同产生最后的请求结果。在复杂的微服务架构系统中,几乎每一个前端请求都会形成一个复杂的分布式服务调用链路。
3 | 那么就带来一系列问题,在业务规模不断增大、服务不断增多以及频繁变更的情况下,如何快速发现问题?如何判断故障影响范围?如何梳理服务依赖以及依赖的合理性?
4 | 如何分析链路性能问题以及实时容量规划?面对上面这些问题,Spring Cloud Sleuth提供了分布式服务跟踪解决方案。本示例代码,包括与Zipkin进行整合,收集方式
5 | 通过http和RabbitMQ两种方式,后面附上博客的地址。
6 |
--------------------------------------------------------------------------------
/trace1-stream/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.primeton
6 | trace1-stream
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | trace1-stream
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-parent
20 | 1.4.2.RELEASE
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.cloud
27 | spring-cloud-dependencies
28 | Brixton.SR5
29 | pom
30 | import
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-web
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-sleuth
43 |
44 |
45 | org.springframework.cloud
46 | spring-cloud-sleuth-stream
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-starter-stream-rabbit
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/trace1-stream/src/main/java/com/primeton/trace1_stream/Trace1Application.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | *
3 | *==============================================================================
4 | *
5 | * Copyright (c) 2001-2016 Primeton Technologies, Ltd.
6 | * All rights reserved.
7 | *
8 | * Created on 2017年9月19日 下午1:47:58
9 | *******************************************************************************/
10 | package com.primeton.trace1_stream;
11 |
12 | import org.apache.log4j.Level;
13 | import org.apache.log4j.Logger;
14 | import org.springframework.boot.SpringApplication;
15 | import org.springframework.boot.autoconfigure.SpringBootApplication;
16 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
17 | import org.springframework.context.annotation.Bean;
18 | import org.springframework.web.bind.annotation.GetMapping;
19 | import org.springframework.web.bind.annotation.RestController;
20 | import org.springframework.web.client.RestTemplate;
21 |
22 | @RestController
23 | @SpringBootApplication
24 | public class Trace1Application {
25 |
26 | private static Logger log = Logger.getLogger(Trace1Application.class);
27 |
28 | @Bean
29 | @LoadBalanced
30 | RestTemplate restTemplate(){
31 | return new RestTemplate();
32 | }
33 |
34 | @GetMapping("/trace3span")
35 | public String callHome() {
36 | log.log(Level.INFO, "calling home");
37 | return restTemplate().getForEntity("http://localhost:8084/trace4span", String.class).getBody();
38 | }
39 |
40 | public static void main(String[] args) {
41 | SpringApplication.run(Trace1Application.class, args);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/trace1-stream/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8083
3 | spring:
4 | rabbitmq:
5 | host: localhost
6 | port: 5672
7 | username: springcloudsleuth
8 | password: 123456
--------------------------------------------------------------------------------
/trace1-stream/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: trace1-stream
--------------------------------------------------------------------------------
/trace1/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.primeton
6 | trace1
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | trace1
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-parent
20 | 1.4.2.RELEASE
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.cloud
27 | spring-cloud-dependencies
28 | Brixton.SR5
29 | pom
30 | import
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-web
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-sleuth
43 |
44 |
45 | org.springframework.cloud
46 | spring-cloud-sleuth-zipkin
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/trace1/src/main/java/com/primeton/trace1/Trace1Application.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | *
3 | *==============================================================================
4 | *
5 | * Copyright (c) 2001-2016 Primeton Technologies, Ltd.
6 | * All rights reserved.
7 | *
8 | * Created on 2017年9月19日 下午1:47:58
9 | *******************************************************************************/
10 | package com.primeton.trace1;
11 |
12 | import org.apache.log4j.Level;
13 | import org.apache.log4j.Logger;
14 | import org.springframework.boot.SpringApplication;
15 | import org.springframework.boot.autoconfigure.SpringBootApplication;
16 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
17 | import org.springframework.context.annotation.Bean;
18 | import org.springframework.web.bind.annotation.GetMapping;
19 | import org.springframework.web.bind.annotation.RestController;
20 | import org.springframework.web.client.RestTemplate;
21 |
22 | @RestController
23 | @SpringBootApplication
24 | public class Trace1Application {
25 |
26 | private static Logger log = Logger.getLogger(Trace1Application.class);
27 |
28 | // @GetMapping("/trace1span1")
29 | // public String callHome1() {
30 | // log.log(Level.INFO, "calling home");
31 | // return "Hello world";
32 | // }
33 |
34 | @Bean
35 | @LoadBalanced
36 | RestTemplate restTemplate() {
37 | return new RestTemplate();
38 | }
39 |
40 | @GetMapping("/trace1span2")
41 | public String callHome2() {
42 | log.log(Level.INFO, "calling home");
43 | return restTemplate().getForEntity("http://localhost:8081/trace2span", String.class).getBody();
44 | }
45 |
46 | public static void main(String[] args) {
47 | SpringApplication.run(Trace1Application.class, args);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/trace1/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8080
3 | spring:
4 | zipkin:
5 | baseUrl: http://localhost:9411/
6 | enabled: true
7 | sleuth:
8 | sampler:
9 | percentage: 1.0
--------------------------------------------------------------------------------
/trace1/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: trace1
--------------------------------------------------------------------------------
/trace2-stream/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.primeton
6 | trace2-stream
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | trace2-stream
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-parent
20 | 1.4.2.RELEASE
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.cloud
27 | spring-cloud-dependencies
28 | Brixton.SR5
29 | pom
30 | import
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-web
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-sleuth
43 |
44 |
45 | org.springframework.cloud
46 | spring-cloud-sleuth-stream
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-starter-stream-rabbit
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/trace2-stream/src/main/java/com/primeton/trace2_stream/Trace2Application.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | *
3 | *==============================================================================
4 | *
5 | * Copyright (c) 2001-2016 Primeton Technologies, Ltd.
6 | * All rights reserved.
7 | *
8 | * Created on 2017年9月19日 下午1:47:58
9 | *******************************************************************************/
10 | package com.primeton.trace2_stream;
11 |
12 | import org.apache.log4j.Level;
13 | import org.apache.log4j.Logger;
14 | import org.springframework.boot.SpringApplication;
15 | import org.springframework.boot.autoconfigure.SpringBootApplication;
16 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
17 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
18 | import org.springframework.context.annotation.Bean;
19 | import org.springframework.web.bind.annotation.GetMapping;
20 | import org.springframework.web.bind.annotation.RestController;
21 | import org.springframework.web.client.RestTemplate;
22 |
23 |
24 | @RestController
25 | @SpringBootApplication
26 | public class Trace2Application {
27 |
28 | private static Logger log = Logger.getLogger(Trace2Application.class);
29 |
30 | @Bean
31 | @LoadBalanced
32 | RestTemplate restTemplate(){
33 | return new RestTemplate();
34 | }
35 |
36 | @GetMapping("/trace4span")
37 | public String home() {
38 | log.log(Level.INFO, "you called home");
39 | return "Hello World";
40 | }
41 |
42 | public static void main(String[] args) {
43 | SpringApplication.run(Trace2Application.class, args);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/trace2-stream/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8084
3 | spring:
4 | rabbitmq:
5 | host: localhost
6 | port: 5672
7 | username: springcloudsleuth
8 | password: 123456
--------------------------------------------------------------------------------
/trace2-stream/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: trace2-stream
--------------------------------------------------------------------------------
/trace2/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.primeton
6 | trace2
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | trace2
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-parent
20 | 1.4.2.RELEASE
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.cloud
27 | spring-cloud-dependencies
28 | Brixton.SR5
29 | pom
30 | import
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-web
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-sleuth
43 |
44 |
45 | org.springframework.cloud
46 | spring-cloud-sleuth-zipkin
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/trace2/src/main/java/com/primeton/trace2/Trace2Application.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | *
3 | *==============================================================================
4 | *
5 | * Copyright (c) 2001-2016 Primeton Technologies, Ltd.
6 | * All rights reserved.
7 | *
8 | * Created on 2017年9月19日 下午1:47:58
9 | *******************************************************************************/
10 | package com.primeton.trace2;
11 |
12 | import org.apache.log4j.Level;
13 | import org.apache.log4j.Logger;
14 | import org.springframework.boot.SpringApplication;
15 | import org.springframework.boot.autoconfigure.SpringBootApplication;
16 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
17 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
18 | import org.springframework.context.annotation.Bean;
19 | import org.springframework.web.bind.annotation.GetMapping;
20 | import org.springframework.web.bind.annotation.RestController;
21 | import org.springframework.web.client.RestTemplate;
22 |
23 | @RestController
24 | @SpringBootApplication
25 | public class Trace2Application {
26 |
27 | private static Logger log = Logger.getLogger(Trace2Application.class);
28 |
29 | @Bean
30 | @LoadBalanced
31 | RestTemplate restTemplate() {
32 | return new RestTemplate();
33 | }
34 |
35 | @GetMapping("/trace2span")
36 | public String home() {
37 | log.log(Level.INFO, "you called home");
38 | return "Hello World";
39 | }
40 |
41 | public static void main(String[] args) {
42 | SpringApplication.run(Trace2Application.class, args);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/trace2/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 | spring:
4 | zipkin:
5 | baseUrl: http://localhost:9411/
6 | enabled: true
--------------------------------------------------------------------------------
/trace2/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: trace2
--------------------------------------------------------------------------------
/zipkinserver-stream/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.primeton
6 | zipkinserver-stream
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | zipkinserver-stream
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-parent
20 | 1.4.2.RELEASE
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.cloud
27 | spring-cloud-dependencies
28 | Brixton.SR5
29 | pom
30 | import
31 |
32 |
33 |
34 |
35 |
36 |
37 | io.zipkin.java
38 | zipkin-server
39 |
40 |
41 | io.zipkin.java
42 | zipkin-autoconfigure-ui
43 |
44 |
45 | org.springframework.cloud
46 | spring-cloud-sleuth-zipkin-stream
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-starter-stream-rabbit
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/zipkinserver-stream/src/main/java/com/primeton/zipkinserver_stream/ZipkinApplication.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | *
3 | *==============================================================================
4 | *
5 | * Copyright (c) 2001-2016 Primeton Technologies, Ltd.
6 | * All rights reserved.
7 | *
8 | * Created on 2017年9月20日 下午1:31:12
9 | *******************************************************************************/
10 |
11 | package com.primeton.zipkinserver_stream;
12 |
13 | import org.springframework.boot.SpringApplication;
14 | import org.springframework.boot.autoconfigure.SpringBootApplication;
15 | import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer;
16 |
17 | import zipkin.server.EnableZipkinServer;
18 |
19 | @EnableZipkinStreamServer
20 | @SpringBootApplication
21 | public class ZipkinApplication {
22 |
23 | public static void main(String[] args) {
24 | SpringApplication.run(ZipkinApplication.class, args);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/zipkinserver-stream/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9411
3 | spring:
4 | application:
5 | name: zipkinserver-stream
--------------------------------------------------------------------------------
/zipkinserver/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.primeton
6 | zipkinserver
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | zipkinserver
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-parent
19 | 1.4.2.RELEASE
20 |
21 |
22 |
23 |
24 |
25 | org.springframework.cloud
26 | spring-cloud-dependencies
27 | Brixton.SR5
28 | pom
29 | import
30 |
31 |
32 |
33 |
34 |
35 |
36 | io.zipkin.java
37 | zipkin-server
38 |
39 |
40 | io.zipkin.java
41 | zipkin-autoconfigure-ui
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/zipkinserver/src/main/java/com/primeton/zipkinserver/ZipkinApplication.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | *
3 | *==============================================================================
4 | *
5 | * Copyright (c) 2001-2016 Primeton Technologies, Ltd.
6 | * All rights reserved.
7 | *
8 | * Created on 2017年9月20日 下午1:31:12
9 | *******************************************************************************/
10 |
11 | package com.primeton.zipkinserver;
12 |
13 | import org.springframework.boot.SpringApplication;
14 | import org.springframework.boot.autoconfigure.SpringBootApplication;
15 |
16 | import zipkin.server.EnableZipkinServer;
17 |
18 | @EnableZipkinServer
19 | @SpringBootApplication
20 | public class ZipkinApplication {
21 |
22 | public static void main(String[] args) {
23 | SpringApplication.run(ZipkinApplication.class, args);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/zipkinserver/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9411
3 | spring:
4 | application:
5 | name: zipkinserver
--------------------------------------------------------------------------------