SpringCloud11-Sleuth

SpringCloud11-Sleuth

1.Sleuth

  1. 在微服务系统中每一个请求都会形成一条复杂的分布式服务调用链路,链路中的任何一环出现高延时或错误都会引起整个请求最后的失败。
  2. Sleuth可以对请求进行链路跟踪,记录处理这个请求的微服务节点和每个微服务处理的时间。
  3. Sleuth官网地址。https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/html/

2.zipkin下载和运行

  1. zipkin出自Twitter,是Sleuth的仪表盘,即图形化界面。
  2. zipkin下载地址。下载地址。https://repo1.maven.org/maven2/io/zipkin/zipkin-server/
  3. zipkin文档地址。https://github.com/openzipkin/zipkin/tree/master/zipkin-server
  4. 下载完成后,通过java -jar zipkin-server-2.23.4-exec.jar运行。
  5. 访问地址。http://localhost:9411/zipkin/

3.zipkin工作流程

  1. 一条链路通过Trace ld唯一标识,Span标识发起的请求信息,各span通过parent id关联起来。
  2. span通过parent id关联起来,span和上一个处理的微服务的span id,形成一个树的关系。
  3. zipkin工作流程图。

image

image

4.创建微服务cloud-euerka-sleuth-zipkin-provider-payment8001

  1. pom.xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zipkin</artifactId>
    <version>2.2.8.RELEASE</version>
</dependency>
  1. yml
server:
  port: 8001

spring:
  application:
    name: cloud-sleuth-payment
  zipkin:
    base-url: http://127.0.0.1:9411
  sleuth:
    sampler:
      # 采用率,介于 0-1直接,1表示所有请求全部采用
      probability: 1
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka
  1. Main、controller不变。
  2. 创建微服务cloud-euerka-sleuth-zipkin-consumer80,配置和cloud-euerka-sleuth-zipkin-provider-payment8001保持一致。
  3. cloud-euerka-sleuth-zipkin-provider-payment8001和cloud-euerka-sleuth-zipkin-consumer80启动后,来模拟服务之间的调用。
  4. 访问http://localhost:9411/zipkin/,查看调用链路追踪。
posted @ 2021-10-07 20:03  行稳致远方  阅读(89)  评论(0)    收藏  举报