全链路spring cloud sleuth+zipkin
http://blog.csdn.net/qq_15138455/article/details/72956232
版权声明:@入江之鲸
一、About ZipKin
please google
二、 Demo Scene
三、 Result Display
四、Prepare
1、soft version
kafka:2.10-0.10.2.0
zokeeper:3.4.10
elasticsearch:5.2.2
jdk:1.8
spring boot:1.5.3.RELEASE
sprign cloud:Dalston.RELEASE
rabbit mq:3.6.9
2、install
kafka+zookeeper
elasticsearch
rabbit mq
mysql
3、create four spring cloud project
web-api、user-api、order-api、zipkin
ps:
why i will create zipkin project use spring boot by myself not use zipkin.jar from http://zipkin.io/,actually,zipkin.jar is a spring boot project,check it's dependency lib you will find it din't use spring-cloud-sleuth-stream,but i will send trace info to kafka for zipkin server collector ,so i must use spring-cloud-sleuth-stream in my service
and the message send to kafka is a sleuth.span object and use kafka default serialized,but zipkin.jar only receive zipkin.span and json or thrift encode,so it‘s not matching,That's the reason i create zipkin server
but if you use rabbit mq,that's no problem.
4、configuration
4.1、the service web-api、user-api、order-api config part like:
pom.xml
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-stream-kafka</artifactId>
- </dependency>
application.properties
- spring.sleuth.sampler.percentage=1.0
- spring.cloud.stream.kafka.binder.brokers=10.20.1.11:9092,10.20.1.12:9092
- spring.cloud.stream.kafka.binder.zkNodes=10.20.1.11:2181,10.20.1.12:2181
4.2、the zipkinconfig part like:
pom.xml
- <!-- the first one dependency below,In principle, there is no need,beause sleuth-zipkin-stream 1.5.3 will Introduce zipkin version1.19 Automaticly,but 1.19 only support elasticsearch version 2.X -->
- <dependency>
- <groupId>io.zipkin.java</groupId>
- <artifactId>zipkin</artifactId>
- <version>1.24.0</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-stream-kafka</artifactId>
- </dependency>
- <dependency>
- <groupId>io.zipkin.java</groupId>
- <artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
- <version>1.24.0</version>
- <optional>true</optional>
- </dependency>
application.properties
- #kafka config
- spring.sleuth.enabled=false
- spring.sleuth.sampler.percentage=1.0
- spring.cloud.stream.kafka.binder.brokers=10.20.1.11:9092,10.20.1.12:9092
- spring.cloud.stream.kafka.binder.zkNodes=10.20.1.11:2181,10.20.1.12:2181
- #elasticsearch config
- zipkin.storage.type=elasticsearch
- zipkin.storage.elasticsearch.hosts=10.20.1.11:9200,10.20.1.12:9200
- zipkin.storage.elasticsearch.cluster=elasticsearch
- zipkin.storage.elasticsearch.index=zipkin
- zipkin.storage.elasticsearch.index-shards=5
- zipkin.storage.elasticsearch.index-replicas=1
ZipKin Server Startup class configuration
- <span style="font-size:14px;">@SpringBootApplication
- //@EnableZipkinServer //this is used by interface receive trace info
- @EnableZipkinStreamServer //can be used kafka,rabbit
- public class ZkingApplication {
- public static void main(String[] args) {
- SpringApplication.run(ZkingApplication.class, args);
- }
- }</span>
五、Demo DownLoad
by the way,spring cloud is a pretty boy,i like its combination of terseness and elegance
六、补充
如果kafka没有启动,spring boot会启动失败,这个异常处理设计的真是缺德
/**
* 1、修改背景
* 因kafka节点没有启动 在spring boot启动时初始化outputBindingLifecycle、inputBindingLifecycle
* 两个bean时候连接kafka失败,向外抛出了异常直到EmbeddedWebApplicationContext类
* 捕获处理,处理方式为:stopAndReleaseEmbeddedServletContainer()导致整个应用停止启动
* 2、修改方案
* 干预上面两个bean的初始化,在连接kafka异常时,将异常处理掉,不向上层抛出
* 3、修改步骤
* 3.1、使用自定义MyBindingLifecycle的bean将BindingServiceConfiguration中的两个bean初始化替换掉
* 3.2、在自定bean中启动线程MyBindingThread来控制两个bean的初始化
* 4、解决启动问题之后,实际上kafka还是没有连接的,此时向kafka发送span时会失败,默认的处理方案是捕获到异常之后使用
* handleError处理,再次发送新的span,这就导致循环发送
* 参见:ErrorHandlingTaskExecutor中的execute方法
* catch (Throwable t)
* {
* ErrorHandlingTaskExecutor.this.errorHandler.handleError(t);
* }
* 5、解决方案
* 重写ErrorHandler的handleError方法
* 6、跟踪代码发现
* 跟踪发现ErrorHandler对线对象是在SourcePollingChannelAdapterFactoryBean初始化时候设置的
* spca.setErrorHandler(this.pollerMetadata.getErrorHandler());
* 进一步发现是在pollerMetadata对象中,所以需要在pollerMetadata对象初始化时候做修改
* 7、修改步骤
* 自定义MyPollerMetadata且需要@Configuration,重写handleError方法如下
* @author zhangdingxin、yangxi
*/
全链路spring cloud sleuth+zipkin的更多相关文章
- 分布式链路追踪之Spring Cloud Sleuth+Zipkin最全教程!
大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第九篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...
- Spring Cloud Alibaba学习笔记(23) - 调用链监控工具Spring Cloud Sleuth + Zipkin
随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请求可能最终需要调用很多次后端服务才能完成,当整个请求陷入性能瓶颈或不可用时,我们是无法得知该请求是由某个或某些后端服务引起的,这时就需要解决如何 ...
- Spring Cloud Sleuth+ZipKin+ELK服务链路追踪(七)
序言 sleuth是spring cloud的分布式跟踪工具,主要记录链路调用数据,本身只支持内存存储,在业务量大的场景下,为拉提升系统性能也可通过http传输数据,也可换做rabbit或者kafka ...
- Spring Cloud Sleuth + Zipkin 链路监控
原文:https://blog.csdn.net/hubo_88/article/details/80878632 在微服务系统中,随着业务的发展,系统会变得越来越大,那么各个服务之间的调用关系也就变 ...
- Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin
前言:随着微服务系统的增加,服务之间的调用关系变得会非常复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得非常重要了.spring cloud sleuth实现了对分布式服务的监控解决 ...
- Spring Cloud Sleuth Zipkin - (1)
最近在学习spring cloud构建微服务,很多大牛都提供很多入门的例子帮助我们学习,对于我们这种英语不好的码农来说,效率着实提高不少.这两天学习到追踪微服务rest服务调用链路的问题,接触到zip ...
- Spring Cloud Sleuth Zipkin - (2)
在上一节<spring-cloud-sleuth+zipkin追踪服务实现(一)>中,我们使用zipkin-server.provider.consumer三个程序实现了使用http方式进 ...
- spring boot 2.0.3+spring cloud (Finchley)7、服务链路追踪Spring Cloud Sleuth
参考:Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin[Finchley 版] Spring Cloud Sleuth 是Spring Cloud的一个组件,主要功能是 ...
- springcloud --- spring cloud sleuth和zipkin日志管理(spring boot 2.18)
前言 在spring cloud分布式架构中,系统被拆分成了许多个服务单元,业务复杂性提高.如果出现了异常情况,很难定位到错误位置,所以需要实现分布式链路追踪,跟进一个请求有哪些服务参与,参与的顺序如 ...
随机推荐
- http://www.ibm.com/developerworks/cn/web/wa-lo-firefox-ext/index.html
<html> <head> <style> textarea{ width:800p ...
- C#小记
1.背景:用fileinput 上传文件 直接上传文件,但有时会发现,这个不上传文件也是可以携带其他参数的, 如果直接用: uploadFile = context.Request.Files[]; ...
- 【简记】HTML + CSS 的一些要点(不定时更新)
1.td占据多行 / 列时,其挤开的 td 不写(但是包裹 td 的 tr 要写) 2. display:td 的元素中的文本默认垂直不居中(table中的td中的文本是垂直居中的) 3.th虽然定义 ...
- (2017.10.10) 我对 JavaScript 历史的认识
关于 JavaScript 的历史和来由相信学过 JavaScript 的小伙伴都能说出一二.我看过一些入门书籍第一章或者前言部分都有介绍,但是一直没捋清这段历史.今天通过两个问题,来加深我对 Jav ...
- Literals
Uppercase or lowercase L means long (however, using a lowercase l is confusing because it can look l ...
- div高度不能自适应(子级使用float浮动,父级div高度不能自适应)
1.问题截图: 2.问题描述: 由于地址.公司名长度的不定性,所以每一条地址所在的父级div高度不定,但是需要设置一个最小的高度min-height:48px;但是当内容增加的时候,父级div高度却不 ...
- SingletonLoginUser
package cn.com.jgt.view{ import flash.errors.IllegalOperationError; /** * actionscript类的构造方法不能是priva ...
- connect() to 192.168.30.71:8082 failed (99: Cannot assign requested address) while connecting to upstream, client: 114.80.182.136, server: localhost, request: "GET /home/senior HTTP/1.1", upstream: "
connect() to 192.168.30.71:8082 failed (99: Cannot assign requested address) while connecting to ups ...
- UVA1610 PartyGame 聚会游戏(细节题)
给出一组字符串D,要找一个字符串S使得D中一半小于等于S,另外一半大于S.输入保证一定有解.长度要尽量短,在此基础上字典序尽量小. 分类谈论,细节挺多的,比如'Z'. 其实直接暴就过了,没分类辣么麻烦 ...
- netbackup如何手动获取主机ID证书。
如何手动获取主机ID证书. 文章:100039650 最后发布:2017-09-21 评分: 20 11 产品:NetBackup 问题 从NetBackup V8.1开始,管理员需要在证书颁发 ...