下载zipkin.jar包

zipkin官网
image.png

运行zipkin服务

image.png

  1. java -jar zipkin-server-2.23.4-exec.jar

访问

  1. http://127.0.0.1:9411

集成springboot

springboot_demo_1

pom.xml

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>io.opentracing.contrib</groupId>
  8. <artifactId>opentracing-spring-zipkin-web-starter</artifactId>
  9. <version>0.1.4</version>
  10. </dependency>
  11. </dependencies>

application.yml

  1. server:
  2. port: 8081
  3. opentracing:
  4. zipkin:
  5. enabled: true
  6. http-sender:
  7. base-url: http://localhost:9411/
  8. spring:
  9. application:
  10. name: springboot_demo1

接口

  1. @RestController
  2. @SpringBootApplication
  3. public class SpringbootDemoApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(SpringbootDemoApplication.class, args);
  6. }
  7. @Resource
  8. RestTemplate restTemplate;
  9. @Bean
  10. public RestTemplate restTemplate() {
  11. return new RestTemplate();
  12. }
  13. @GetMapping("/hii")
  14. public String helloDocker() {
  15. return restTemplate.getForObject("http://127.0.0.1:8082/hi", String.class);
  16. }
  17. }

springboot_demo_2

pom.xml

同上

application.yml

  1. server:
  2. port: 8082
  3. opentracing:
  4. zipkin:
  5. enabled: true
  6. http-sender:
  7. base-url: http://localhost:9411/
  8. spring:
  9. application:
  10. name: springboot_demo2

接口

  1. @RestController
  2. @SpringBootApplication
  3. public class SpringbootDemoApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(SpringbootDemoApplication.class, args);
  6. }
  7. @GetMapping("/hi")
  8. public String helloDocker() {
  9. return "hello docker";
  10. }
  11. }

启动服务

springboot_demo_1
springboot_demo_2

调用接口

image.png

zipkin查看

image.png