SpringCloudAlibaba-整合sleuth和zipkin(六)

目录地址:

SpringCloudAlibaba整合-CSDN博客

一、整合sleuth

1.引入依赖

在需要追踪的微服务中引入依赖,user、order、product

XML 复制代码
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

2.启动微服务;访问服务接口;可以看到order的控制台信息

绿色部分INFO,就是链路信息,参数:

参数一:微服务名称,spring.application.name 的值

参数二:表示 本次请求的链路追踪 id(Trace ID),本次请求涉及多个下游服务,链路追踪 id 相同,表示这些都是同一次追踪

参数三:表示 当前服务本次链路追踪的 id(Span ID),本次请求涉及多个下游服务,每个微服务的 Span ID 都不相同,代表不同的服务。

二、整合zipkin

1.安装并启动zipkin,可以自己下载,这里使用docker版

bash 复制代码
docker pull openzipkin/zipkin

docker run --name zipkin -p 9411:9411 openzipkin/zipkin -d

2.在3个微服务模块添加依赖

XML 复制代码
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zipkin</artifactId>
     <!--zipkin 是第三方的,版本和 spring cloud 不同步,所以要指定版本-->
     <version>2.2.8.RELEASE</version>    
</dependency>

3.添加配置

XML 复制代码
spring:
  zipkin:
    # 配置 zipkin 服务所在地址
    base-url: http://localhost:9411
    # 不开启服务发现
    discovery-client-enabled: false
    sender:
      type: web
  sleuth:
    sampler:
      # 配置 sleuth 链路追踪采样 百分比,1:百分百,0.1:百分之十。采样比例过高影响性能
      probability: 0.1

4.启动微服务,访问order的接口,查看zipkin页面,可以点进去看详情

访问之后,过一会才能看到信息

5.zipkin的持久化

参考:https://cloud.tencent.com/developer/article/2318336

相关推荐
短剑重铸之日2 天前
《SpringCloud实用版》Stream + RocketMQ 实现可靠消息 & 事务消息
后端·rocketmq·springcloud·消息中间件·事务消息
没有bug.的程序员4 天前
Spring Cloud Stream:消息驱动微服务的实战与 Kafka 集成终极指南
java·微服务·架构·kafka·stream·springcloud·消息驱动
没有bug.的程序员5 天前
Spring Cloud Gateway:API网关限流与熔断实战
java·开发语言·数据库·spring boot·gateway·api·springcloud
wfsm9 天前
nacos和openfeign
springcloud
无心水9 天前
【分布式利器:腾讯TSF】11、腾讯TSF微服务框架深度对比:全面解析TSF vs Spring Cloud vs Dubbo vs Service Mesh
分布式·spring cloud·微服务·dubbo·springcloud·service mesh·分布式利器
sunnyday042610 天前
Spring Cloud Alibaba Sentinel 流量控制与熔断降级实战指南
spring boot·sentinel·springcloud
悟空码字13 天前
Spring Cloud 集成 Nacos,全面的配置中心与服务发现解决方案
java·nacos·springcloud·编程技术·后端开发
坐不住的爱码19 天前
Bootstrap和application.yml
springcloud
悟空码字20 天前
Spring Cloud Gateway实战,从零搭建API网关,构建高性能微服务统一入口
java·gateway·springcloud·编程技术·后端开发
没有bug.的程序员21 天前
Service Mesh 与 Spring Cloud 共存方案:双体系治理、平滑迁移与风险控制实战指南
云原生·springcloud·流量治理·混合架构·servicemesh·微服务迁移·技术演进