本文共 2506 字,大约阅读时间需要 8 分钟。
博客参考学习视频: https://www.bilibili.com/video/BV18E411x7eT?from=search&seid=4388336378730572330
上一篇:
在微服务框架中,一个由客户端发起的请求在后端系统中会经过多个不同的服务点调用来协同产生最后的请求结果,每一个前端请求都会形成一条复杂的分布式服务调用链路,链路中的任何一环出现高延迟或错误都会引起整个请求最后的失败。
Spring Cloud Sleuth 提供了一套完整的服务跟踪的解决方案,在分布式系统中提供追踪解决方案并且兼容支持了 zipkin。
运行 jar
运行控制台
完整的调用链路
上图 what
名词解释
Trace: 类似于树结构的Span 集合,表示一条调用链路,存在唯一标识
span: 表示调用链路来源,通俗的理解 span 就是一次请求信息
cloud-provider-payment8001
POM
org.springframework.cloud spring-cloud-starter-zipkin
YML
server: port: 8001spring: application: name: cloud-payment-service zipkin: base-url: http://localhost:9411 sleuth: sampler: #采样率值介于 0 到 1 之间,1 则表示全部采集 probability: 1 datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/db2019?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC username: root password: 6090mybatis: mapperLocations: classpath:mapper/*.xml type-aliases-package: com.oy.springcloud.entities # 所有Entity别名类所在包eureka: client: register-with-eureka: true fetch-registry: true service-url: # 集群版 defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka instance: instance-id: payment8001 prefer-ip-address: true
业务类 PaymentController
// ====================> zipkin+sleuth@GetMapping("/payment/zipkin")public String paymentZipkin(){ return "hi ,i'am paymentzipkin server fall back,welcome to atguigu,O(∩_∩)O哈哈~";}
cloud-consumer-order80
POM
org.springframework.cloud spring-cloud-starter-zipkin
YML
zipkin: base-url: http://localhost:9411 sleuth: sampler: probability: 1
业务类 OrderController
@GetMapping("/consumer/payment/zipkin")public String paymentZipkin(){ String result = restTemplate.getForObject("http://localhost:8001"+"/payment/zipkin/", String.class); return result;}
80 调用 8001 几次测试下 : http://localhost/consumer/payment/zipkin
会出现以下界面
查看依赖关系
原理
会出现以下界面
[外链图片转存中…(img-kK5NjTgJ-1603429001501)]
[外链图片转存中…(img-X77scIx2-1603429001503)]
查看依赖关系
原理
转载地址:http://yabki.baihongyu.com/