继SpringCloud Sleuth-CSDN博客
使用RabbitMQ收集链路数据
引导
通过Spring Cloud Sleuth整合Zipkin,已经实现了通过HTTP方式收集链路跟踪信息,除了使用HTTP方式之外,还可以使用RabbitMQ消息中间件异步收集链路跟踪信息。本节讲解如何通过RabbitMQ收集链路信息。
使用RabbitMQ收集链路数据
1.下载zipkin.jar
官网下载不稳定,这里为了方便下载我已放百度网盘
通过网盘分享的文件:zipkin-server-2.23.9-exec.jar
链接: https://pan.baidu.com/s/1mkmx0Lu05qdMMCxdPPvLcw 提取码: utr3
--来自百度网盘超级会员v4的分享
2.启动zipkin.jar
在jar包放置路径下,输入cmd
然后,输入此行:java -jar zipkin-server-2.23.9-exec.jar --zipkin.collector.rabbitmq.addresses=localhost
3.对已有的工程进行改造
1.要启动rabbitMQ
2.在这三个工程中加入rabbitmq的依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency>
4.测试运行
测试前,先把自己写的zipkin关掉
访问此路径:http://localhost:9410/eureka-consumer/hi
Zipkin启动成功后,使用浏览器访问http://127.0.0.1:15762。我们会发现RabbitMQ控制台中的 Queues选项中可以看到多了一个“zipkin”队列,说明Zipkin Server与RabbitMQ之间建立了通信。
整合MySQL存储链路数据实现持久化
1.修改Zipkin服务端
依赖:
<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-server</artifactId><version>2.11.8</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-sleuth</artifactId></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-autoconfigure-ui</artifactId><version>2.11.8</version></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-autoconfigure-storage-mysql</artifactId><version>2.11.5</version></dependency><dependency><groupId>io.zipkin.zipkin2</groupId><artifactId>zipkin-storage-mysql-v1</artifactId><version>2.11.5</version></dependency><dependency><groupId>org.jooq</groupId><artifactId>jooq</artifactId><version>3.11.4</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-dbcp2</artifactId><version>2.3.0</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
application.yml
server:port: 9411
spring:application:name: zipkin-serverdatasource:url: jdbc:mysql://localhost:3306/zipkin?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8username: rootpassword: rootdriver-class-name: com.mysql.jdbc.Driverdbcp2:initial-size: 50max-wait-millis: 60000max-idle: 100default-auto-commit: truedefault-read-only: falsetest-on-borrow: truetype: org.apache.commons.dbcp2.BasicDataSourcerabbitmq:host: localhostport: 5672username: guestpassword: guest
eureka:client:service-url:defaultZone: http://localhost:7000/eureka/
management:metrics:web:server:auto-time-requests: false
zipkin:storage:type: mysql
SQL文件:
通过网盘分享的文件:zipkin.sql
链接: https://pan.baidu.com/s/1L8n0fMAtcFfy32QLYaibPQ 提取码: p3hb
--来自百度网盘超级会员v4的分享
2.启动测试
所有模块运行启动后
访问http://localhost:9410/eureka-consumer/hi
就会存入数据库表中,这样就表示整合MySQL存储链路数据持久化成功!!