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

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.cloud</groupId>
  7. <artifactId>spring-cloud-starter-stream-kafka</artifactId>
  8. </dependency>

application.properties

  1. spring.sleuth.sampler.percentage=1.0
  2. spring.cloud.stream.kafka.binder.brokers=10.20.1.11:9092,10.20.1.12:9092
  3. spring.cloud.stream.kafka.binder.zkNodes=10.20.1.11:2181,10.20.1.12:2181

4.2、the zipkinconfig part like:

pom.xml

  1. <!-- 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 -->
  2. <dependency>
  3. <groupId>io.zipkin.java</groupId>
  4. <artifactId>zipkin</artifactId>
  5. <version>1.24.0</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework.cloud</groupId>
  9. <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.cloud</groupId>
  13. <artifactId>spring-cloud-starter-stream-kafka</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>io.zipkin.java</groupId>
  17. <artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
  18. <version>1.24.0</version>
  19. <optional>true</optional>
  20. </dependency>

application.properties

  1. #kafka config
  2. spring.sleuth.enabled=false
  3. spring.sleuth.sampler.percentage=1.0
  4. spring.cloud.stream.kafka.binder.brokers=10.20.1.11:9092,10.20.1.12:9092
  5. spring.cloud.stream.kafka.binder.zkNodes=10.20.1.11:2181,10.20.1.12:2181
  6. #elasticsearch config
  7. zipkin.storage.type=elasticsearch
  8. zipkin.storage.elasticsearch.hosts=10.20.1.11:9200,10.20.1.12:9200
  9. zipkin.storage.elasticsearch.cluster=elasticsearch
  10. zipkin.storage.elasticsearch.index=zipkin
  11. zipkin.storage.elasticsearch.index-shards=5
  12. zipkin.storage.elasticsearch.index-replicas=1

ZipKin Server Startup class configuration

  1. <span style="font-size:14px;">@SpringBootApplication
  2. //@EnableZipkinServer //this is used by interface receive trace info
  3. @EnableZipkinStreamServer //can be used kafka,rabbit
  4. public class ZkingApplication {
  5. public static void main(String[] args) {
  6. SpringApplication.run(ZkingApplication.class, args);
  7. }
  8. }</span>

五、Demo DownLoad

click me

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的更多相关文章

  1. 分布式链路追踪之Spring Cloud Sleuth+Zipkin最全教程!

    大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第九篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...

  2. Spring Cloud Alibaba学习笔记(23) - 调用链监控工具Spring Cloud Sleuth + Zipkin

    随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请求可能最终需要调用很多次后端服务才能完成,当整个请求陷入性能瓶颈或不可用时,我们是无法得知该请求是由某个或某些后端服务引起的,这时就需要解决如何 ...

  3. Spring Cloud Sleuth+ZipKin+ELK服务链路追踪(七)

    序言 sleuth是spring cloud的分布式跟踪工具,主要记录链路调用数据,本身只支持内存存储,在业务量大的场景下,为拉提升系统性能也可通过http传输数据,也可换做rabbit或者kafka ...

  4. Spring Cloud Sleuth + Zipkin 链路监控

    原文:https://blog.csdn.net/hubo_88/article/details/80878632 在微服务系统中,随着业务的发展,系统会变得越来越大,那么各个服务之间的调用关系也就变 ...

  5. Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin

    前言:随着微服务系统的增加,服务之间的调用关系变得会非常复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得非常重要了.spring cloud sleuth实现了对分布式服务的监控解决 ...

  6. Spring Cloud Sleuth Zipkin - (1)

    最近在学习spring cloud构建微服务,很多大牛都提供很多入门的例子帮助我们学习,对于我们这种英语不好的码农来说,效率着实提高不少.这两天学习到追踪微服务rest服务调用链路的问题,接触到zip ...

  7. Spring Cloud Sleuth Zipkin - (2)

    在上一节<spring-cloud-sleuth+zipkin追踪服务实现(一)>中,我们使用zipkin-server.provider.consumer三个程序实现了使用http方式进 ...

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

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

  9. springcloud --- spring cloud sleuth和zipkin日志管理(spring boot 2.18)

    前言 在spring cloud分布式架构中,系统被拆分成了许多个服务单元,业务复杂性提高.如果出现了异常情况,很难定位到错误位置,所以需要实现分布式链路追踪,跟进一个请求有哪些服务参与,参与的顺序如 ...

随机推荐

  1. [转] java实现https请求

    package com.lichmama.test.util; import java.io.ByteArrayOutputStream; import java.io.IOException; im ...

  2. JavaScript中登录名的正则表达式及解析(0基础)

    简言 在JavaScript中,经常会用到正则表达式来进行模式匹配.例如,登录名验证,密码强度验证,字符串查找或替换等操作.现在就开始吧,零基础写出你的第一个正则表达式! 在做用户注册时,都会用到登录 ...

  3. Python+Selenium与Chrome如何进行完美结合

    zhuan:http://blog.51cto.com/starpoint/2102975?cid=704621 使用WebDriver在Chrome浏览器上进行测试时,需要从http://chrom ...

  4. uvm_mem_mam——寄存器模型(十三)

    有了存储器模型,再来看看存储器的管理 //------------------------------------------------------------------------------ ...

  5. Linux下端口被占用如何解决???

    有时候关闭软件后,后台进程死掉,导致端口被占用.下面以JBoss端口8083被占用为例,列出详细解决过程. 解决方法: 1.查找被占用的端口 netstat -tln netstat -tln | g ...

  6. 一点对Promise的理解与总结

    全手打原创,转载请标明出处:https://www.cnblogs.com/dreamsqin/p/10959411.html,多谢,=.=~ axios用多了就开始疑惑它里面到底是个啥,虽然总被告知 ...

  7. java面试题(杨晓峰)---第一讲谈谈你对java平台的理解

    本人总结: 面向对象(封装,继承,多态) 平台无关性(jvm运行,class文件) 语言(泛型,lambda) 类库(集合,并发,网络,io/nio) jre(java运行环境,JVM,类库) JDK ...

  8. MySQL基础教程——创建数据库并插入数据

    本节将介绍 MySQL 新建数据库,新建表,插入数据以及基本数据类型的相关知识.本节实验将创建一个名为 mysql_shiyan 的数据库,其中有两张表 employee和 department. 1 ...

  9. groupdel - Delete a group

    总览 SYNOPSIS groupdel group 描述 DESCRIPTION groupdel 命令会修改系统帐号档,会删除所有指定群组的信息 . 群组名须存在. 你须手动确认一下所有的档案系统 ...

  10. Launch Instance---source for openstack

    If you want to create an instance that uses ephemeral storage, meaning the instance data is lost whe ...