sleuth与zipkin入门章节中,zipkin client的数据通过http的方式发送到服务端。http是阻塞式请求,如果zipkin server处理的效率低,直接导致业务服务延迟高或者返回超时,此时可以通过在client和server中间增加消息队列实现异步数据采集,如RabbitMQ或者Kafka。这里使用RabbitMQ示例。
dokcer pull registry.cn-beijing.aliyuncs.com/buyimoutianxia/rabbitmq:V3.7.25 docker run -it -d --name rabbitmq / -p 5672:5672 -p 15672:15672 / -e RABBITMQ_DEFAULT_USER=admin / -e RABBITMQ_DEFAULT_PASS=admin / registry.cn-beijing.aliyuncs.com/buyimoutianxia/rabbitmq:V3.7.25 #解决http://localhost:15672的网址打不开的问题 docker exec -it rabbitmq sh -co "rabbitmq-plugins enable rabbitmq_management" 复制代码
#拉取阿里云个人镜像仓库 docker pull registry.cn-beijing.aliyuncs.com/buyimoutianxia/zipkin:2.11 docker run -d --name zipkin -p 9411:9411 / -e RABBIT_ADDRESSES=172.17.0.2:5672 / -e RABBIT_USER=admin / -e RABBIT_PASSWORD=admin / registry.cn-beijing.aliyuncs.com/buyimoutianxia/zipkin:2.11 复制代码
<!--rabbitmq--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin</artifactId> </dependency> <dependency> <groupId>org.springframework.amqp</groupId> <artifactId>spring-rabbit</artifactId> </dependency> 复制代码
spring: application: name: microservice-provider #微服务名称 #修改zipkin使用rabbitmq采集数据 zipkin: # base-url: http://localhost:9411 # zipkin server地址和端口 sender: type: rabbit # 向rabbit中发送消息 # type: web #zipkin消息传送发送方式,采用Http协议: sleuth: sampler: probability: 1 # sleuth配置采样比,默认是0.1 rabbitmq: host: localhost port: 5672 username: admin password: admin listener: #重试策略 direct: retry: enabled: true simple: retry: enabled: true 复制代码