一.服務端(最新版本官方不建議自己寫服務端,建議直接使用編譯好的jar,通過啟動參數來配置)
下載下傳位址:https://repo1.maven.org/maven2/io/zipkin/java/zipkin-server
1.pom.xml中依賴
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tanjun</groupId>
<artifactId>zipkin-server</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.15.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
<version>2.8.4</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
2.yaml檔案配置
spring:
application:
name: zipkin-server
server:
port: 9411
3.啟動類
SpringBootApplication
@EnableZipkinServer
public class Application {
public static void main(String[] args) {
SpringApplication springApplication=new SpringApplication(Application.class);
springApplication.run(args);
}
}
4.驗證
輸入:localhost:9411
二.用戶端
1.pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tanjun</groupId>
<artifactId>eureka-client</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.15.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!---Eureka遠端服務所需要的依賴-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!--調用鍊用戶端所需要的依賴-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<!--健康檢查所需要的依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2. yml檔案
server:
port: 8080
spring:
application:
name: eureka-client
zipkin:
base-url: http://localhost:9411
sleuth:
trace-id128: true
sampler:
percentage: 1
#健康檢查
management:
security:
enabled: false
endpoints:
actuator:
enabled: true
health:
sensitive: true
3.需要注意點:需要配置http請求相關的bean
@Component
public class HttpConfig {
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
4.測試
@RequestMapping("hello")
public String hello() throws InterruptedException {
Thread.sleep(3000L);
String s=restTemplate.getForEntity("http://www.baidu.com",String.class).getBody();
System.out.println(s);
Thread.sleep(1000L);
return restTemplate.getForEntity("http://www.baidu.com",String.class).getBody();
}