0
点赞
收藏
分享

微信扫一扫

【Spring Cloud、Sleuth、Zipkin】搭建Spirng Cloud项目(九):Spring Cloud使用Sleuth + Zipkin进行服务链路追踪

Separes 2022-03-16 阅读 92

一、环境准备

1、环境搭建,查看Spring Cloud专栏

2、(前提)准备一个服务提供方(sys-server)的接口和服务调用方(security-oauth2-server)接口,本文是在文章【Spring Cloud、OpenFeign】搭建Spirng Cloud项目(七):Spring Cloud使用OpenFeign调用其他服务中进行扩展。

二、功能介绍

参考文章:服务链路追踪(Spring Cloud Sleuth)

三、代码

背景:本文提供的是通过OpenFegin调用服务提供方请求实现该演示,自己可以通过RestTemplate直接调用服务提供方的请求实现该演示。

1、改造sys-server服务

  • pom依赖(推荐直接放在父级pom中)
		<!--包含了sleuth+zipkin-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
  • application.yml中添加配置
spring:
  zipkin:
    # Zipkin地址
    base-url: http://localhost:7004
    sleuth:
      sampler:
      probability: 1

2、改造security-oauth2-server服务

  • pom依赖(推荐直接放在父级pom中)
		<!--包含了sleuth+zipkin-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
  • application.yml中添加配置
spring:
  zipkin:
    # Zipkin地址
    base-url: http://localhost:7004
    sleuth:
      sampler:
      probability: 1

四、服务重启

  • Postman调用服务调用方(security-oauth2-server)接口(客户端 -> 请求security-oauth2-server服务,security-oauth2-server服务 -> 请求sys-server服务)
    在这里插入图片描述
  • ZipKin界面展示
    在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

五、问题总结

六、拓展

推荐文章:SpringCloud Sleuth分布式请求链路追踪

举报

相关推荐

0 条评论