搭建链路监控步骤
服务提供者
以我们之前的模块cloud-provider-payment8001
为例Eureka7001单机版
pom
添加zipkin依赖,包含了sleuth
1 2 3 4 5
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
|

yml
spring.zikpin.base-url
zipkin地址
spring.sleuth.sampler.probability
采样率 值介于 0 到 1 之间,1 则表示全部采集

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| server: port: 8001
spring: application: name: cloud-payment-service zipkin: base-url: http://localhost:9411 sleuth: sampler: probability: 1 datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/springcloud?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: kylin
mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.kylin.entities
eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:7001/eureka instance: instance-id: payment8001 prefer-ip-address: true
|
controller

1 2 3 4
| @GetMapping("/payment/zipkin") public String paymentZipkin(){ return "hi,I am paymentZipkin server fallback,welcome to here,(*^_^*)"; }
|
服务消费者
修改我们之前的模块cloud-consumer-order80
pom
添加zipkin依赖,包含了sleuth
1 2 3 4 5
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
|
yml

controller

1 2 3 4 5 6 7
| @GetMapping("/consumer/payment/zipkin") public String paymentZipkin() { String result = restTemplate.getForObject("http://localhost:8001"+"/payment/zipkin/", String.class); return result; }
|
测试
启动7001 80 8001
)
多次访问客户端http://localhost/consumer/payment/zipkin
调用服务提供者提供的服务

访问http://localhost:9411/zipkin/
,选择cloud-order-service

可能到我们发送的请求

点进第一个,就能看到请求链路了。

测试成功!