服务端
一、集成docker外部的mysql,rabbitmq的docker-compose.yml的配置如下
# This file uses the version 2 docker-compose file format, described here:
# https://docs.docker.com/compose/compose-file/#version-2
#
# This runs the zipkin and zipkin-mysql containers, using docker-compose's
# default networking to wire the containers together.
#
# Note that this file is meant for learning Zipkin, not production deployments.
version: '2'
services:
zipkin:
image: openzipkin/zipkin
container_name: zipkin
# Environment settings are defined here https://github.com/openzipkin/zipkin/tree/1.19.0/zipkin-server#environment-variables
environment:
- STORAGE_TYPE=mysql
# Point the zipkin at the storage backend
- MYSQL_DB=shop_zipkin
- MYSQL_USER=root
- MYSQL_PASS=root
- MYSQL_HOST=192.168.1.81
- MYSQL_TCP_PORT=3306
# Uncomment to enable scribe
# - SCRIBE_ENABLED=true
# Uncomment to enable self-tracing
# - SELF_TRACING_ENABLED=true
# Uncomment to enable debug logging
# - JAVA_OPTS=-Dlogging.level.zipkin=DEBUG -Dlogging.level.zipkin2=DEBUG
- RABBIT_ADDRESSES=192.168.1.81:5672
- RABBIT_USER=guest
- RABBIT_PASSWORD=guest
- RABBIT_QUEUE=zipkin
- RABBIT_VIRTUAL_HOST=/admin_host
ports:
# Port used for the Zipkin UI and HTTP Api
- 9411:9411
# Uncomment if you set SCRIBE_ENABLED=true
# - 9410:9410
二、docker配置完docker-compose.yml启动zipkin服务端镜像(下载,启动)
zipkin启动可参考文章https://blog.csdn.net/qq_42714869/article/details/90052903
三、zipkin服务端启动成功后rabbitmq会生成消息队列,如下图
客户端ZipkinClient
一、Maven依赖
<!-- ZipkinClient集成 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!-- ZipkinClient集成rabbitMQ -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<!-- 添加springboot对amqp的支持,RabbitMQ依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
二、application.yml配置
spring:
application:
name: app-shop-member
###zipkin链路监控与追踪
zipkin:
base-url: http://192.168.1.81:9411/
###全部采集
sleuth:
sampler:
probability: 1.0
####集成rabbitmq
rabbitmq:
####连接地址
host: 192.168.1.81
####端口号
port: 5672
####账号
username: guest
####密码
password: guest
### 地址
virtual-host: /admin_host
###开启消息确认机制 confirms
publisher-confirms: true
publisher-returns: true