SpringCloud微服务(07):Zipkin组件,实现请求链路追踪

Easter79
• 阅读 561

本文源码:GitHub·点这里 || GitEE·点这里

一、链路追踪简介

1、Sleuth组件简介

Sleuth是SpringCloud微服务系统中的一个组件,实现了链路追踪解决方案。可以定位一个请求到底请求了哪些具体的服务。在复杂的微服务系统中,如果请求发生了异常,可以快速捕获问题所在的服务。

2、项目结构

  • 启动顺序如下

    • 注册中心 node07-eureka-7001
    • 链路数据收集服务 node07-zipkin-7003
    • 服务提供 node07-provider-6001 node07-provider-6002
    • 网关路由 node07-zuul-7002

二、搭建链路服务

1、核心依赖

<dependency>
    <groupId>io.zipkin.java</groupId>
    <artifactId>zipkin-server</artifactId>
</dependency>
<dependency>
    <groupId>io.zipkin.java</groupId>
    <artifactId>zipkin-autoconfigure-ui</artifactId>
</dependency>
  • 启动类注解:@EnableZipkinServer

2、配置文件

server:
  port: 7003
spring:
  application:
    name: node07-zipkin-7003
eureka:
  instance:
    hostname: zipkin-7003
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://registry01.com:7001/eureka/

三、服务配置

这里网关,zuul-7002,服务提供,provider-6001,provider-6002的配置相同。

1、核心依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

2、配置文件

spring:
  zipkin:
    base-url: http://localhost:7003
  sleuth:
    sampler:
      # 数据 100% 上传
      percentage: 1.0

四、测试流程

1、注册中心

一次启动上述服务之后,查看注册中心:

SpringCloud微服务(07):Zipkin组件,实现请求链路追踪

2、请求流程

访问接口

http://localhost:7002/v1/api-6001/get6001Info

这个请求从网关服务进入,到达6001端口服务之后,请求6002端,最终返回结果。

  • 6001接口

    @Autowired private RestTemplate restTemplate ; @RequestMapping("/get6001Info") public String get6001Info (){ String server_name = "http://node07-provider-6002" ; return restTemplate.getForObject(server_name+"/get6002Info",String.class) ; }

  • 6002接口

    @RequestMapping(value = "/get6002Info",method = RequestMethod.GET) public String get6002Info () { LOG.info("provider-6002"); return "6002Info" ; }

3、链路管理界面

1)、UI界面

访问接口

http://localhost:7003/zipkin/

SpringCloud微服务(07):Zipkin组件,实现请求链路追踪

2)、依赖分析

如图点击,【依赖分析】,和上面描述的请求过程完全一致。 SpringCloud微服务(07):Zipkin组件,实现请求链路追踪

五、源代码地址

GitHub·地址
https://github.com/cicadasmile/spring-cloud-base
GitEE·地址
https://gitee.com/cicadasmile/spring-cloud-base

SpringCloud微服务(07):Zipkin组件,实现请求链路追踪

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
2年前
SpringCloud微服务:阿里开源组件Nacos,服务和配置管理
源码地址:GitHub·点这里(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fcicadasmile%2Fspringcloudbase)||GitEE·点这里(https://gitee.com/cicadasmile/springcloudba
Easter79 Easter79
2年前
SpringCloud微服务:基于Nacos组件,整合Dubbo框架
源码地址:GitHub·点这里(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fcicadasmile%2Fspringcloudbase)||GitEE·点这里(https://gitee.com/cicadasmile/springcloud
Easter79 Easter79
2年前
SpringCloud实现分库分表模式下,数据库实时扩容方案
本文源码:GitHub·点这里(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fcicadasmile%2Fspringcloudbase)||GitEE·点这里(https://gitee.com/cicadasmile/springcloud
Stella981 Stella981
2年前
SpringBoot2 整合Ehcache组件,轻量级缓存管理
本文源码:GitHub·点这里(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fcicadasmile%2Fmiddlewareparent)||GitEE·点这里(https://gitee.com/cicadasmile/middleware
Easter79 Easter79
2年前
SpringCloud基础组件总结,与Dubbo框架、SpringBoot框架对比分析
本文源码:GitHub·点这里(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fcicadasmile%2Fspringcloudbase)||GitEE·点这里(https://gitee.com/cicadasmile/springcloud
Wesley13 Wesley13
2年前
Java描述设计模式(09):装饰模式
本文源码:GitHub·点这里(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fcicadasmile)||GitEE·点这里(https://gitee.com/cicadasmile)一、生活场景1、场景描述
Easter79 Easter79
2年前
SpringCloud微服务:Sentinel哨兵组件,管理服务限流和降级
源码地址:GitHub·点这里(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fcicadasmile%2Fspringcloudbase)||GitEE·点这里(https://gitee.com/cicadasmile/springcloudba
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k