Spring Boot 2.0 + zipkin 分布式跟踪系统快速入门
原文: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 分布式跟踪系统快速入门的更多相关文章
- Spring Boot 2.x(十七):快速入门Elastic Search
What -- Elasticsearch是什么? Elasticsearch是一个基于Lucene的搜索服务器,Elasticsearch也是使用Java编写的,它的内部使用Lucene做索引与搜索 ...
- Zipkin分布式跟踪系统介绍
Zipkin是什么Zipkin分布式跟踪系统:它可以帮助收集时间数据,解决在microservice架构下的延迟问题:它管理这些数据的收集和查找:Zipkin的设计是基于谷歌的Google Dappe ...
- 微服务之分布式跟踪系统(springboot+zipkin+mysql)
通过上一节<微服务之分布式跟踪系统(springboot+zipkin)>我们简单熟悉了zipkin的使用,但是收集的数据都保存在内存中重启后数据丢失,不过zipkin的Storage除了 ...
- spring boot 2.0.3+spring cloud (Finchley)7、服务链路追踪Spring Cloud Sleuth
参考:Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin[Finchley 版] Spring Cloud Sleuth 是Spring Cloud的一个组件,主要功能是 ...
- 业余草分享 Spring Boot 2.0 正式发布的新特性
就在昨天Spring Boot2.0.0.RELEASE正式发布,今天早上在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误, ...
- spring boot / cloud (十五) 分布式调度中心进阶
spring boot / cloud (十五) 分布式调度中心进阶 在<spring boot / cloud (十) 使用quartz搭建调度中心>这篇文章中介绍了如何在spring ...
- spring boot / cloud (十六) 分布式ID生成服务
spring boot / cloud (十六) 分布式ID生成服务 在几乎所有的分布式系统或者采用了分库/分表设计的系统中,几乎都会需要生成数据的唯一标识ID的需求, 常规做法,是使用数据库中的自动 ...
- springboot2.0(一):【重磅】Spring Boot 2.0权威发布
就在昨天Spring Boot2.0.0.RELEASE正式发布,今天早上在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误, ...
- Spring Boot 2.0系列文章(七):SpringApplication 深入探索
关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/30/springboot_SpringApplication/ 前言 在 Spring B ...
随机推荐
- 从requests源码分析中学习python(一)
v2ex同步更新:https://www.v2ex.com/t/500081 微信公众号:python学习开发 分析源码,看大神的代码是一种学习的好方法,让我从中学到很多以前不知道的知识,这次打算从大 ...
- [Android]使用 Eclipse 给 APK 签名时遇到的两个问题及解决办法
问题 今天用 APK 反编译工具看了一下自己项目生成的 APK 文件,发现代码并没有混淆,于是设置了用 ProGuard 混淆代码,可是混淆是必须在非 Debug 模式才会生效的,即使你是以 Rele ...
- Ubuntu 12.04 安装Tomcat7
1.下载Tomcat7 打开Tomcat官网 http://tomcat.apache.org,在左边的导航栏的“Download"中找到Tomcat7.0目录,点击后进入Tomcat7的页 ...
- linux进程的一些日常处理
linux 下查看一个进程运行路径的方法 在linux下查看进程大家都会想到用 ps -ef|grep XXX 可是看到的不是全路径,怎么看全路径呢? 每个进程启动之后在 /proc下面有一个于pid ...
- 算法笔记(C++)
一.基础篇 C++标准模板库(STL) 1.vector 可以理解为“变长数组” #include <vector> vector<typename> name; vector ...
- 1 、在Linux(centos6.8)系统下的JDK安装与配置
一.解压jdk安装包: 附上jdk1.8的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-21 ...
- linux中如何清空一个文件的内容
方法1: echo "" > /www.jbxue.com /xxx.log 方法2: echo "" >> /www.jbxue.com / ...
- 棋盘游戏 HDU1281
一开始毫无思路 看了题解才发现是二分图的最大匹配问题 行为n 列为m 行列匹配 (一行只能与一列匹配 这点和象棋的车的意义一样) 再去掉点看看最大匹配会不会少 如果少了说明为关键点 其中 ...
- 000 关于IDEA的基本环境配置以及快速使用(git拉载程序,Jdk安装,tomcat部署,应用程序打包运行)
刚开始工作的时候,不熟悉,所以整理过这个文档. 一:导入git程序 1.准备 git链接 IDEA软件,最好是终极版 2.第一步选择从版本控制上选择git 3.拷贝源于目标地址 4.这时候根据引导进行 ...
- WebStorm failing to start with 'idea.system.path' error
WebStorm failing to start with 'idea.system.path' error Ask Question up vote 2 down vote favorite ...