一、首先说问题:

  • 1、springCloud在使用链路追踪组件sleuth整合zipkin的过程中链路追踪信息切都是正常;
  • 2、微服务太多需要使用组件Config对每个微服务的的配置文件进行统一管理;
  • 3、config对微服务进行管理,但是如果某一个配置发生改变,如果每个微服务都要重启才能获取最新的配置文件就不合理,那么springCloud提供了spring cloud Bus组件来刷新配置,使用消息中间件(官方推荐RabbitMQ)不需要重启微服务就可以获取最新配置。
  • 4、当spring cloud Bus 配置完成之后zipkin完全收集不到链路追踪信息了。。。

二、寻找解决方案

最开始遇到这个问题时,认为是自己配置在哪里有问题,反复确认没有问题。然后开始狂论坛,问大牛。得到的答案是springcloud不成熟,可能存在bug,既然有bug(我也不知道该怎么解决),但是如果链路追踪不能使用,对整个微服务的调用依赖,每个微服务的调用请求耗时就没有办法定位,对后期的维护是不利的。只能放弃分布式配置,但是也不好,如果修改了一个配置文件,每个微服务都要重启,对于后期的维护也是不利的。只能继续寻找解决方案。

三、问题分析

  • 1、出现这个问题,首先想到的是要去官方文档上寻找答案;丢一个springcloud文档:springcloud Finchley SR2。
  • 2、使用springcloud Bus需要使用rabbitMQ,但是zipkin收集信息是http(文档)
If you want both Sleuth and Zipkin, add the spring-cloud-starter-zipkin dependency.The following example shows how to do so for Maven:Maven. <dependencyManagement> 1<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${release.train.version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement><dependency> 2<groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
1、We recommend that you add the dependency management through the Spring BOM so that you need not manage versions yourself.2、Add the dependency to spring-cloud-starter-zipkin.

同时zipkin也支持使用RabbitMQ来收集链路信息,猜想是不是在配置中使用了RabbitMQ收集,而HTTP的方式失效了,那么就有两个解决方案:其中一就是只是用HTTP的方式,不是用RabbitMQ;二:就是将zipkin收集链路信息的方式修改为RabbitMQ。方式一简单有效,但是没有找到相应的配置,那么就使用方案二,在官方文档中也有描述将zipkin的获取方式修改为rabbitMq或者kafka:

If you want to use RabbitMQ or Kafka instead of HTTP, add the spring-rabbit or spring-kafka dependency. The default destination name is zipkin.If using Kafka, you must set the property spring.zipkin.sender.type property accordingly:spring.zipkin.sender.type: kafka
[Caution]   Caution
spring-cloud-sleuth-stream is deprecated and incompatible with these destinations.If you want Sleuth over RabbitMQ, add the spring-cloud-starter-zipkin and spring-rabbit dependencies.The following example shows how to do so for Gradle:Maven. <dependencyManagement> 1<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${release.train.version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement><dependency> 2<groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency> 3<groupId>org.springframework.amqp</groupId><artifactId>spring-rabbit</artifactId>
</dependency>
1、We recommend that you add the dependency management through the Spring BOM so that you need not manage versions yourself.2、Add the dependency to spring-cloud-starter-zipkin. That way, all nested dependencies get downloaded.3、To automatically configure RabbitMQ, add the spring-rabbit dependency.

通过官方文档的说明按照上述的三个步骤就能实现,但是按照上述的步骤依旧是没有追踪到链路信息。

上述的配置说明微服务的客户端应该是没有问题的,那么问题可能出现在zipkin服务器上。

四、zipkin服务器的问题

从spring boot 2.0开始官方就官方不再支持使用自建Zipkin Server的方式进行服务链路追踪,而是直接提供了编译好的 jar 包来给我们使用。
但是从1.0时代的配置中应该是可以看出问题,在1.0的Zipkin Service中需要加入sleuth和rabbit的依赖,同时需要配置rabbitMQ消息的地址,但是使用jar包直接启动,并没有指定rabbit的地址。
查询spring-cloud-sleuth在github上的源码,在源码中会有一些人遇到一些问题,会不会有同样的问题,解决方案。其中有一个问题:

Question: How to configure Sleuth with Zipkin over RabbitMQ

有一个回答:

I also have the same problem and the workaround provided in Gitter has helped me to solve it until the permanent solution is in place. For the benefit of others here is the workaround.Explicitly configure spring.rabbitmq.addresses property to point to the credentials of the bounded RabbitMQ service. For example, if the bounded service is called rabbitmq the following configuration will work:spring.rabbitmq.addresses=${vcap.services.rabbitmq.credentials.uri}

也就是说在启动zipkin的时候指定一下rabbitMq的地址。问题

五、解决方案

1、在需要收集链路追踪的客户端添加依赖:

        <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId></dependency><dependency><groupId>org.springframework.amqp</groupId><artifactId>spring-rabbit</artifactId></dependency>

2、下载zipk的jar包这里使用了zipkin-server-2.11.1-exec
在启动zipkin的之后设置参数

java -jar zipkin.jar --zipkin.collector.rabbitmq.addresses=localhost

或者使用docker
添加参数

docker run -d -e zipkin.collector.rabbitmq.addresses=localhost -p 9411:9411 openzipkin/zipkin

在docker启动后还是有问题,最后发现是localhost的问题,将localhost修改成rabbit对应的服务器IP地址就好了。
启动之后在RabbitMq中会出现一个zipkin的队列。

另一种方式,使用http就比较简单,在项目中加入

  zipkin:base-url: http://ip:9411# 使用http的方式收集链路追踪信息,默认是使用rabbitMQ,这样在使用了spring cloud Bus之后链路追踪就不会失效了sender:type: web

但是推荐使用rabbit。
最后在zipkin的页面上就可以看到链路追踪的信息了

Spring cloud(Finchley)微服务框架,sleuth整合zipkin链路追踪失效的问题相关推荐

  1. Spring Cloud Alibaba 微服务开发实践

    作者:禅与计算机程序设计艺术 1.简介 Spring Cloud Alibaba 是阿里巴巴开源的基于 Spring Cloud 的微服务框架.该项目从最初孵化到现在已经历经十多年的发展,得到了广泛的 ...

  2. 《深入理解 Spring Cloud 与微服务构建》第十二章 服务注册和发现 Consul

    <深入理解 Spring Cloud 与微服务构建>第十二章 服务注册和发现 Consul 文章目录 <深入理解 Spring Cloud 与微服务构建>第十二章 服务注册和发 ...

  3. Spring Cloud构建微服务架构:分布式服务跟踪(整合zipkin)【Dalston版】

    通过上一篇<分布式服务跟踪(整合logstash)>,我们虽然已经能够利用ELK平台提供的收集.存储.搜索等强大功能,对跟踪信息的管理和使用已经变得非常便利.但是,在ELK平台中的数据分析 ...

  4. Spring Cloud构建微服务架构:分布式服务跟踪(整合logstash)【Dalston版】

    通过之前的<入门示例>,我们已经为两个由SpringCloud构建的微服务项目 trace-1和 trace-2引入了Spring Cloud Sleuth的基础模块 spring-clo ...

  5. 《深入理解 Spring Cloud 与微服务构建》第十四章 服务链路追踪 Spring Cloud Sleuth

    <深入理解 Spring Cloud 与微服务构建>第十四章 服务链路追踪 Spring Cloud Sleuth 文章目录 <深入理解 Spring Cloud 与微服务构建> ...

  6. 即插即用!开源项目【云框架】发布“基于Spring cloud的微服务架构”

    开发者面对新技术无非两个场景,一是不懂技术想要学习,二是懂技术想要使用. 前者需要考虑如何快速掌握技术原理并能把技术用起来,而后者需要琢磨如何花费最小代价将技术应用于生产环境. 换句话说,想要获得新技 ...

  7. 从0到1 手把手搭建spring cloud alibaba 微服务大型应用框架(三) (mini-cloud) 搭建认证服务(认证/资源分离版) oauth2.0 (中)

    本文承接上文<从0到1 手把手搭建spring cloud alibaba 微服务大型应用框架(三) (mini-cloud) 搭建认证服务(认证/资源分离版) oauth2.0 (上)> ...

  8. 从0到1手把手搭建spring cloud alibaba 微服务大型应用框架(十五) swagger篇 : gateway 集成swagger 与 knife4j实现在线api文档并嵌入到自己项目内

    背景 我们日常开发中基本都是协同开发的,当然极个别的项目整体前后端都是一个人开发的,当多人协作时,尤其是前后端人员协同开发时 必然会面临着前端需要了解后端api接口的情况,两个选择,提前设计好文档,然 ...

  9. 干货|基于 Spring Cloud 的微服务落地

    转载自 干货|基于 Spring Cloud 的微服务落地 微服务架构模式的核心在于如何识别服务的边界,设计出合理的微服务.但如果要将微服务架构运用到生产项目上,并且能够发挥该架构模式的重要作用,则需 ...

最新文章

  1. VS2005中ajax安装指南[转]
  2. 算法导论-动态规划(dynamic programming)
  3. ansible的模块使用
  4. bzoj千题计划262:bzoj4868: [六省联考2017]期末考试
  5. 浅谈 Python 中的多线程。
  6. 上海php黑名单,php判断ip黑名单程序代码实例
  7. POJ2186-Popular Cows(流行的奶牛)【tarjan,强连通分量,图论】
  8. 06软件构架实践阅读笔记之六
  9. PHP中的数组建必须为数字吗,PHP检查数组中缺少的数字
  10. jupyter notebook 中添加 Julia kernel
  11. Pytorch nn.functional.unfold()的简单理解与用法
  12. Python中字符串反转的一个简单操作
  13. Hbase Cellutil源码
  14. tableView选中行的调用顺序/ 取消选中Cell
  15. 使用 Java8的 stream对list数据去重,使用filter()过滤列表,list转map
  16. java 普通方法_Java普通方法与static方法的多态
  17. 快速破解rar解压密码
  18. python zip压缩文件下载及解压
  19. 离散实验sdut3805双射
  20. luoguP2711 小行星

热门文章

  1. Cpp 对象模型探索 / 带有虚继承类的构造函数的调用顺序
  2. 小明分享|WiFi协议迭代历程
  3. android 上传头像遇到的问题,Android 7.0 图片剪切问题,选择头像上传
  4. php 插入数据 不成功,thinkphp5连接oracle用insert插入数据失败
  5. tab css html,纯css的tab 切换
  6. Dreamweaver的HTML语言标记,Dreamweaver
  7. android硬编码封装mp4,【Android 音视频开发打怪升级:音视频硬解码篇】四、音视频解封和封装:生成一个MP4...
  8. ajax刷新数据库数据,ajax删除数据刷新数据库
  9. 可信计算 沈昌祥_沈昌祥:用可信计算筑牢网络安全
  10. Linux内核--网络协议栈深入分析(二)--sk_buff的操作函数