Skip to content

Commit 19777fd

Browse files
author
feiweiwei
committed
add sleuth demo
1 parent 10d66ee commit 19777fd

12 files changed

Lines changed: 354 additions & 0 deletions

File tree

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<module>hystrixclient</module>
1313
<module>hystrixturbine</module>
1414
<module>hystrixclientrabbitmq</module>
15+
<module>tomcat-apr</module>
16+
<module>sleuth-testservice1</module>
17+
<module>sleuth-testservice2</module>
18+
<module>zipkin-server</module>
1519
</modules>
1620

1721

sleuth-testservice1/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.monkey01.springcloud</groupId>
6+
<artifactId>sleuth-testservice1</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<!-- 引入spring boot的依赖 -->
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.7.RELEASE</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-eureka</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-ribbon</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.cloud</groupId>
37+
<artifactId>spring-cloud-starter-sleuth</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.cloud</groupId>
41+
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
42+
</dependency>
43+
</dependencies>
44+
45+
<!-- 引入spring cloud的依赖 -->
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.springframework.cloud</groupId>
50+
<artifactId>spring-cloud-dependencies</artifactId>
51+
<version>Camden.SR4</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
58+
<!-- 添加spring-boot的maven插件 -->
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-maven-plugin</artifactId>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.monkey01.testservice;
2+
3+
import com.netflix.discovery.DiscoveryClient;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7+
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.web.client.RestTemplate;
10+
11+
/**
12+
* @author: feiweiwei
13+
* @description:
14+
* @created Date: 10:01 18/6/11.
15+
* @modify by:
16+
*/
17+
@SpringBootApplication
18+
@EnableDiscoveryClient
19+
public class Application {
20+
@Bean
21+
@LoadBalanced
22+
RestTemplate restTemplate(){
23+
return new RestTemplate();
24+
}
25+
26+
public static void main(String[] args) {
27+
SpringApplication.run(Application.class, args);
28+
}
29+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.monkey01.testservice.controller;
2+
3+
import com.netflix.discovery.DiscoveryClient;
4+
import org.apache.log4j.Logger;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.cloud.client.ServiceInstance;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
import org.springframework.web.bind.annotation.RestController;
10+
import org.springframework.web.client.RestTemplate;
11+
12+
import java.util.List;
13+
14+
/**
15+
* @author: feiweiwei
16+
* @description:
17+
* @created Date: 10:02 18/6/11.
18+
* @modify by:
19+
*/
20+
@RestController
21+
public class TestController1 {
22+
private final Logger logger = Logger.getLogger(getClass());
23+
@Autowired
24+
private RestTemplate restTemplate;
25+
@Autowired
26+
private DiscoveryClient discoveryClient;
27+
28+
29+
@RequestMapping(value = "/testController1", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
30+
public String testController1(){
31+
List<String> list = discoveryClient.getDiscoveryServiceUrls("registry");
32+
for(String url : list){
33+
System.out.println(url + "===");
34+
}
35+
logger.info("===call testController1===");
36+
return restTemplate.getForEntity("http://SLEUTH-TESTSERVICE2/testController2", String.class).getBody();
37+
}
38+
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
server:
2+
port: 9091
3+
spring:
4+
application:
5+
name: sleuth-testservice1
6+
zipkin:
7+
base-url: http://localhost:9411
8+
eureka:
9+
client:
10+
serviceUrl:
11+
defaultZone: http://10.132.33.43:8761/eureka/
12+
# defaultZone: http://localhost:8761/eureka/

sleuth-testservice2/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.monkey01.springcloud</groupId>
6+
<artifactId>sleuth-testservice2</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<!-- 引入spring boot的依赖 -->
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.7.RELEASE</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-eureka</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-ribbon</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.cloud</groupId>
37+
<artifactId>spring-cloud-starter-sleuth</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.cloud</groupId>
41+
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
42+
</dependency>
43+
</dependencies>
44+
45+
<!-- 引入spring cloud的依赖 -->
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.springframework.cloud</groupId>
50+
<artifactId>spring-cloud-dependencies</artifactId>
51+
<version>Camden.SR4</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
58+
<!-- 添加spring-boot的maven插件 -->
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-maven-plugin</artifactId>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package testservice;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
7+
/**
8+
* @author: feiweiwei
9+
* @description:
10+
* @created Date: 10:01 18/6/11.
11+
* @modify by:
12+
*/
13+
@SpringBootApplication
14+
@EnableDiscoveryClient
15+
public class Application {
16+
public static void main(String[] args) {
17+
SpringApplication.run(Application.class, args);
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package testservice.controller;
2+
3+
import org.apache.log4j.Logger;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* @author: feiweiwei
10+
* @description:
11+
* @created Date: 10:02 18/6/11.
12+
* @modify by:
13+
*/
14+
@RestController
15+
public class TestController2 {
16+
private final Logger logger = Logger.getLogger(getClass());
17+
18+
@RequestMapping(value = "/testController2", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
19+
public String testController2(){
20+
logger.info("===call testController2===");
21+
return "TestService2";
22+
}
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server:
2+
port: 9092
3+
spring:
4+
application:
5+
name: sleuth-testservice2
6+
zipkin:
7+
base-url: http://localhost:9411
8+
eureka:
9+
client:
10+
serviceUrl:
11+
defaultZone: http://10.132.33.43:8761/eureka/

zipkin-server/pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.monkey01.springcloud</groupId>
6+
<artifactId>zipkin-server</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<!-- 引入spring boot的依赖 -->
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.7.RELEASE</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>io.zipkin.java</groupId>
25+
<artifactId>zipkin-server</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>io.zipkin.java</groupId>
29+
<artifactId>zipkin-autoconfigure-ui</artifactId>
30+
</dependency>
31+
</dependencies>
32+
33+
<!-- 引入spring cloud的依赖 -->
34+
<dependencyManagement>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.springframework.cloud</groupId>
38+
<artifactId>spring-cloud-dependencies</artifactId>
39+
<version>Camden.SR4</version>
40+
<type>pom</type>
41+
<scope>import</scope>
42+
</dependency>
43+
</dependencies>
44+
</dependencyManagement>
45+
46+
<!-- 添加spring-boot的maven插件 -->
47+
<build>
48+
<plugins>
49+
<plugin>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-maven-plugin</artifactId>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>

0 commit comments

Comments
 (0)