博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringCloud Sleuth 分布式请求链路
阅读量:3968 次
发布时间:2019-05-24

本文共 2506 字,大约阅读时间需要 8 分钟。

博客参考学习视频: https://www.bilibili.com/video/BV18E411x7eT?from=search&seid=4388336378730572330

上一篇:

一、概述

① 为什么会出现这个技术? 需要解决哪些问题?

​ 在微服务框架中,一个由客户端发起的请求在后端系统中会经过多个不同的服务点调用来协同产生最后的请求结果,每一个前端请求都会形成一条复杂的分布式服务调用链路,链路中的任何一环出现高延迟或错误都会引起整个请求最后的失败。

② 是什么

Spring Cloud Sleuth 提供了一套完整的服务跟踪的解决方案,在分布式系统中提供追踪解决方案并且兼容支持了 zipkin。

③ 解决

image-20201023114955011

二、搭建链路监控步骤

① zipkin 下载

  1. SpringCloud 从 F 版起已不需要自己构建 Zipkin server 了,只需要调用 jar 包即可
  2. https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server/
  3. zipkin-server-2.12.9.exec.jar

运行 jar

image-20201023115255023

运行控制台

  1. http://localhost:9411/zipkin/

image-20201023115912407

  1. 术语

完整的调用链路

image-20201023115937720

上图 what

image-20201023120436405

名词解释

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

image-20201023123521600

业务类 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

image-20201023124242263

业务类 OrderController

@GetMapping("/consumer/payment/zipkin")public String paymentZipkin(){
String result = restTemplate.getForObject("http://localhost:8001"+"/payment/zipkin/", String.class); return result;}

④ 依次启动 eureka7001/8001/80

80 调用 8001 几次测试下 : http://localhost/consumer/payment/zipkin

⑤ 打开浏览器访问:http:localhost:9411

会出现以下界面

image-20201023125051624

image-20201023125202606

查看依赖关系

原理

⑤ 打开浏览器访问:http:localhost:9411

会出现以下界面

[外链图片转存中…(img-kK5NjTgJ-1603429001501)]

[外链图片转存中…(img-X77scIx2-1603429001503)]

查看依赖关系

原理

image-20201023125237541

转载地址:http://yabki.baihongyu.com/

你可能感兴趣的文章
Flutter 插件笔记 | 屏幕适配 flutter_screenutil
查看>>
Flutter UI基础 - 侧拉抽屉菜单
查看>>
Flutter UI基础 - AppBar中标题文字如何居中
查看>>
Flutter UI基础 - Drawer 抽屉视图与自定义header
查看>>
Flutter UI基础 - GridView
查看>>
Flutter UI基础 - 使用InkWell给任意Widget添加点击事件
查看>>
OC WKWebView的使用
查看>>
Flutter UI基础 - Image.asset 图片铺满布局
查看>>
Flutter UI基础 - Row、Column详解
查看>>
Flutter UI基础 - 添加背景图片
查看>>
Flutter UI基础 - 布局之Row/Column/Stack
查看>>
Flutter UI基础 - 层叠布局Stack的使用
查看>>
Go - 解决 go get 超时问题
查看>>
SQL - SQL Server 之遍历数据集合的几种方法
查看>>
SQL - SQL Server 之处理JSON数据
查看>>
SQL - SQL Server 之WHILE循环的坑
查看>>
SQL - SQL Server 性能优化之SQL语句总结
查看>>
Docker - docker-compose常用命令
查看>>
SQL - SQL Server判断字符串中是否有中文
查看>>
SQL - SQL Server查询近7天的连续日期
查看>>