众所周知,Spring Cloud Sleuth有两种方式整合Zipkin:
Spring Cloud Edgware及更高版本中,Sleuth使用MQ方式整合Zipkin的玩法发生了巨大改变。本文将贴出新旧版本中Sleuth如何整合Zipkin的具体操作。MQ使用的是RabbitMQ(读者也可使用Kafka)。
如果您使用Spring Cloud Dalston或更低版本,那么整合步骤如下:
一、依赖:
<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>
二、启动类上添加注解 @EnableZipkinStreamServer
。
三、配置:
server:
port: 9411
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
一、加依赖:
<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>
二、配置:
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
对于Edgware,以上方式也可使用,但目前已标注为 废弃
,未来将被删除!
从Edgware开始,应如下整合Zipkin——
一、依赖:
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>
<version>2.3.1</version>
</dependency>
二、启动类上添加 @EnableZipkinServer
。
三、配置:
server:
port: 9411
zipkin:
collector:
rabbitmq:
addresses: localhost:5672
password: guest
username: guest
queue: zipkin
一、依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
二、配置:
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
zipkin:
rabbitmq:
queue: zipkin
对比后不难发现,从Edgware开始,Sleuth基于MQ整合Zipkin更加的简化!不过,改动还是比较大的。官方为什么要做这个改进呢?答案如下——
Zipkin1.x
,要想MQ方式收集数据,需整合 spring-cloud-sleuth-stream
。而在Edgware及更高版本中,使用 Zipkin2.x
。 Zipkin2.x
本身已支持基于MQ的数据收集方式,故而 spring-cloud-sleuth-stream
将被废弃!本文分享自 A周立SpringCloud 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!