原文:https://www.jianshu.com/p/9bfe103418e2

注意

Spring Boot 2.0之后,使用EnableZipkinServer创建自定义的zipkin服务器已经被废弃,将无法启动
具体可看issue
Deprecates EnableZipkinServer to explain custom servers are unsupported

开始

搭建zipkin服务器

获取最新发布的zipkin服务器,一个可执行的jar

curl -sSL https://zipkin.io/quickstart.sh | bash -s

然后启动它

java -jar zipkin.jar

也可以通过docker来启动

docker run -d -p 9411:9411 openzipkin/zipkin

启动后就可以在浏览器打开http://your_host:9411/zipkin/查看了。

创建两个服务

pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<sleuth.version>2.0.0.RELEASE</sleuth.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Sleuth automatically adds trace interceptors when in the classpath -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<!-- Sends trace data to zipkin over http (defaults to http://localhost:9411/api/v2/spans) -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth</artifactId>
<version>${sleuth.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Backend.java

@EnableAutoConfiguration
@RestController
public class Backend { @RequestMapping("/api") public String printDate() {
return new Date().toString() + " by hongxi";
} public static void main(String[] args) {
SpringApplication.run(Backend.class,
"--spring.application.name=backend",
"--server.port=9000"
);
}
}

Frontend.java

@EnableAutoConfiguration
@RestController
@CrossOrigin // So that javascript can be hosted elsewhere
public class Frontend { @Autowired RestTemplate restTemplate; @RequestMapping("/") public String callBackend() {
return restTemplate.getForObject("http://localhost:9000/api", String.class);
} @Bean RestTemplate restTemplate() {
return new RestTemplate();
} public static void main(String[] args) {
SpringApplication.run(Frontend.class,
"--spring.application.name=frontend",
"--server.port=8081"
);
}
}

application.properties

spring.sleuth.traceId128=true
spring.sleuth.sampler.probability=1.0

然后分别启动Backen和Frontend,在浏览器访问http://localhost:8080/,可以看到页面显示

Wed Jun 20 16:47:00 CST 2018 by hongxi

说明调用成功,然后回到http://your_host:9411/zipkin/点击大大的那个按钮“Find Traces”即可看到调用跟踪信息。

 
 

 

Spring Boot 2.0 + zipkin 分布式跟踪系统快速入门的更多相关文章

  1. Spring Boot 2.x(十七):快速入门Elastic Search

    What -- Elasticsearch是什么? Elasticsearch是一个基于Lucene的搜索服务器,Elasticsearch也是使用Java编写的,它的内部使用Lucene做索引与搜索 ...

  2. Zipkin分布式跟踪系统介绍

    Zipkin是什么Zipkin分布式跟踪系统:它可以帮助收集时间数据,解决在microservice架构下的延迟问题:它管理这些数据的收集和查找:Zipkin的设计是基于谷歌的Google Dappe ...

  3. 微服务之分布式跟踪系统(springboot+zipkin+mysql)

    通过上一节<微服务之分布式跟踪系统(springboot+zipkin)>我们简单熟悉了zipkin的使用,但是收集的数据都保存在内存中重启后数据丢失,不过zipkin的Storage除了 ...

  4. spring boot 2.0.3+spring cloud (Finchley)7、服务链路追踪Spring Cloud Sleuth

    参考:Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin[Finchley 版] Spring Cloud Sleuth 是Spring Cloud的一个组件,主要功能是 ...

  5. 业余草分享 Spring Boot 2.0 正式发布的新特性

    就在昨天Spring Boot2.0.0.RELEASE正式发布,今天早上在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误, ...

  6. spring boot / cloud (十五) 分布式调度中心进阶

    spring boot / cloud (十五) 分布式调度中心进阶 在<spring boot / cloud (十) 使用quartz搭建调度中心>这篇文章中介绍了如何在spring ...

  7. spring boot / cloud (十六) 分布式ID生成服务

    spring boot / cloud (十六) 分布式ID生成服务 在几乎所有的分布式系统或者采用了分库/分表设计的系统中,几乎都会需要生成数据的唯一标识ID的需求, 常规做法,是使用数据库中的自动 ...

  8. springboot2.0(一):【重磅】Spring Boot 2.0权威发布

    就在昨天Spring Boot2.0.0.RELEASE正式发布,今天早上在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误, ...

  9. Spring Boot 2.0系列文章(七):SpringApplication 深入探索

    关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/30/springboot_SpringApplication/ 前言 在 Spring B ...

随机推荐

  1. HighCharts、EChart图表X轴纵向显示

    HighCharts 回调javascript函数来格式化标签,值通过this.value获得,this的其他属性还包括axis, chart, isFirst and isLast. 默认为: fu ...

  2. list的几种new方式比较ImmutableList

    数组的非空判断: -----数组的非空判断----- StringUtils.isNotBlank(array); list的非空判断: -----list的非空判断----- CollectionU ...

  3. Java 接口关键字 interface

    interface这个关键字产生一个完全抽象的类,它根本就没有提供任何具体的实现,它允许创建者确定方法名.参数列表和返回类型,但没有任何方法体,接口只提供了形式,而未提供任何具体实现 一个接口表示:& ...

  4. spfa学习笔记

    序 spfa它死了 --by 大佬 但是本蒟蒻还是一如既往的使用spfa... 因为太弱了,其他什么都不会.于是就疯狂开O2跪倒在spfa上. 例题--汽车加油行驶问题 loj跳转链接 luogu跳转 ...

  5. 主席树初步学习笔记(可持久化数组?静态区间第k大?)

    我接触 OI也快1年了,然而只写了3篇博客...(而且还是从DP跳到了主席树),不知道我这个机房吊车尾什么时候才能摸到大佬们的脚后跟orz... 前言:主席树这个东西,可以说是一种非常畸形的数据结构( ...

  6. PHP字符串指定位置插入字符串

    1.substr_replace(string,replacement,start,length);需插入时设置length为0即可 string 必需.规定要检查的字符串. replacement ...

  7. 谈谈MySQL中的降序索引 order by id DESC / ASC

    今天这篇主要讲order by 语句中的多个字段asc desc的问题.mysql5中,索引存储的排序方式是ASC的,没有DESC的索引.现在能够理解为啥order by 默认是按照ASC来排序的了吧 ...

  8. HashMap几个需要注意的知识点

    HashMap简介 HashMap 是java集合框架的一部分. key value都允许null值 (除了非同步和允许使用 null 之外,HashMap 类与 Hashtable 大致相同) 不保 ...

  9. Java集合&Spring源码浅读

    记录自己现在知道的,以后了解了更多的话,再继续补上来 Java集合类 Collection 接口 说明:是List,set 的父类.定义了集合初始模样.集合只存储对象. Jdk8文档,内部方法定义有: ...

  10. maven执行update命令时报org/apache/maven/shared/filtering/MavenFilteringException错误

    原 maven执行update命令时报org/apache/maven/shared/filtering/MavenFilteringException错误 在eclipse中对准项目执行maven- ...