Spring Cloud Edgware新特性之九:Sleuth使用MQ方式整合Zipkin

简介: 众所周知,Spring Cloud Sleuth有两种方式整合Zipkin:HTTP直连Zipkin方式MQ方式,架构图如下:image.pngSpring Cloud Edgware及更高版本中,Sleuth使用MQ方式整合Zipkin的玩法发生了巨大改变。

众所周知,Spring Cloud Sleuth有两种方式整合Zipkin:

  • HTTP直连Zipkin方式

  • MQ方式,架构图如下:

image.png

Spring Cloud Edgware及更高版本中,Sleuth使用MQ方式整合Zipkin的玩法发生了巨大改变。本文将贴出新旧版本中Sleuth如何整合Zipkin的具体操作。MQ使用的是RabbitMQ(读者也可使用Kafka)。

Dalston及更低版本

如果您使用Spring Cloud Dalston或更低版本,那么整合步骤如下:

服务器端

  1. 依赖:

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
    </dependency>
    <dependency>
      <groupId>io.zipkin.java</groupId>
      <artifactId>zipkin-autoconfigure-ui</artifactId>
    </dependency>
    
    AI 代码解读
  2. 启动类上添加注解@EnableZipkinStreamServer

  3. 配置:

    server:
      port: 9411
    spring:  
      rabbitmq:
        host: localhost
        port: 5672
        username: guest
        password: guest
    
    AI 代码解读

微服务端

  1. 加依赖:

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-sleuth-stream</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
    </dependency>
    
    AI 代码解读
  2. 配置:

    spring:
      rabbitmq:
        host: localhost
        port: 5672
        username: guest
        password: guest
    
    AI 代码解读

Edgware及更高版本

对于Edgware,以上方式也可使用,但目前已标注为废弃 ,未来将被删除!

从Edgware开始,应如下整合Zipkin——

服务器端

  1. 依赖:

    <dependency>
      <groupId>io.zipkin.java</groupId>
      <artifactId>zipkin-autoconfigure-ui</artifactId>
    </dependency>
    <dependency>
      <groupId>io.zipkin.java</groupId>
      <artifactId>zipkin-server</artifactId>
    </dependency>
    
    <!-- 使用消息的方式收集数据(使用rabbitmq) -->
    <dependency>
      <groupId>io.zipkin.java</groupId>
      <artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>
      <version>2.3.1</version>
    </dependency>
    
    AI 代码解读
  2. 启动类上添加@EnableZipkinServer

  3. 配置:

    server:
      port: 9411
    zipkin:
      collector:
        rabbitmq:
          addresses: localhost:5672
          password: guest
          username: guest
          queue: zipkin
    
    AI 代码解读

微服务端

  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>
    
    AI 代码解读
  2. 配置:

    spring:
      rabbitmq:
        host: localhost
        port: 5672
        username: guest
        password: guest
      zipkin:
        rabbitmq:
          queue: zipkin
    
    AI 代码解读

对比及分析

对比后不难发现,从Edgware开始,Sleuth基于MQ整合Zipkin更加的简化!不过,改动还是比较大的。官方为什么要做这个改进呢?答案如下——

  1. Spring Cloud Edgware之前的版本使用Zipkin 1.x ,要想MQ方式收集数据,需整合spring-cloud-sleuth-stream 。而在Edgware及更高版本中,使用Zipkin 2.xZipkin 2.x 本身已支持基于MQ的数据收集方式,故而spring-cloud-sleuth-stream 将被废弃!
  2. 两种使用方式不兼容,请读者务必注意!
相关实践学习
消息队列RocketMQ版:基础消息收发功能体验
本实验场景介绍消息队列RocketMQ版的基础消息收发功能,涵盖实例创建、Topic、Group资源创建以及消息收发体验等基础功能模块。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
目录
打赏
0
0
0
0
29
分享
相关文章
微服务SpringCloud链路追踪之Micrometer+Zipkin
SpringCloud+Openfeign远程调用,并用Mircrometer+Zipkin进行链路追踪
406 20
如何将Spring Boot + RabbitMQ应用程序部署到Pivotal Cloud Foundry (PCF)
如何将Spring Boot + RabbitMQ应用程序部署到Pivotal Cloud Foundry (PCF)
54 6
基于MicrometerTracing门面和Zipkin实现集成springcloud2023的服务追踪
Sleuth将会停止维护,Sleuth最新版本也只支持springboot2。作为替代可以使用MicrometerTracing在微服务中作为服务追踪的工具。
230 1
监控与追踪:如何利用Spring Cloud Sleuth和Netflix OSS工具进行微服务调试
监控与追踪:如何利用Spring Cloud Sleuth和Netflix OSS工具进行微服务调试
85 1
微服务架构师的福音:深度解析Spring Cloud RocketMQ,打造高可靠消息驱动系统的不二之选!
【8月更文挑战第29天】Spring Cloud RocketMQ结合了Spring Cloud生态与RocketMQ消息中间件的优势,简化了RocketMQ在微服务中的集成,使开发者能更专注业务逻辑。通过配置依赖和连接信息,可轻松搭建消息生产和消费流程,支持消息过滤、转换及分布式事务等功能,确保微服务间解耦的同时,提升了系统的稳定性和效率。掌握其应用,有助于构建复杂分布式系统。
102 0
Sleuth+Zipkin 实现 SpringCloud 链路追踪
【8月更文挑战第9天】Sleuth+Zipkin 实现 SpringCloud 链路追踪
169 1
Sleuth+Zipkin 实现 SpringCloud 链路追踪
Spring Boot 2.x新特性有哪些?
【7月更文挑战第16天】Spring Boot 2.x新特性有哪些?
123 1
实现Spring Boot与RabbitMQ消息中间件的无缝集成
实现Spring Boot与RabbitMQ消息中间件的无缝集成
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等