SpringCloud Sleuth分布式请求链路跟踪,java运维工程师面试题

编程知识 更新时间:2023-04-07 03:36:47

http://localhost:9411/zipkin/

一条链路通过Trace Id唯一标识,Span标识发起的请求信息,各span通过parent id 关联起来。

Trace:类似于树结构的Span集合,表示一条调用链路,存在唯一标识。

span:表示调用链路来源,通俗的理解span就是一次请求信息。

2、服务提供者


(1)cloud-provider-payment8001

(2)POM

org.springframework.cloud

spring-cloud-starter-zipkin

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

(3)YML

server:

port: 8001

spring:

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: org.gjt.mm.mysql.Driver # mysql驱动包

url: jdbc:mysql://localhost:3306/db2019?useUnicode=true&characterEncoding=utf-8&useSSL=false

username: root

password: 123456

eureka:

client:

#表示是否将自己注册进EurekaServer默认为true。

register-with-eureka: true

#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡

fetchRegistry: true

service-url:

#defaultZone: http://eureka7001:7001/eureka,http://eureka7002:7002/eureka # 集群版

defaultZone: http://localhost:7001/eureka # 单机版

instance:

instance-id: payment8001

#访问路径可以显示IP地址

prefer-ip-address: true

#Eureka客户端向服务端发送心跳的时间间隔,单位为秒(默认是30秒)

lease-renewal-interval-in-seconds: 1

#Eureka服务端在收到最后一次心跳后等待时间上限,单位为秒(默认是90秒),超时将剔除服务

lease-expiration-duration-in-seconds: 2

mybatis:

mapperLocations: classpath:mapper/*.xml

type-aliases-package: com.atguigu.springcloud.entities # 所有Entity别名类所在包

(4)业务类PaymentController

@GetMapping("/payment/zipkin")

public String paymentZipkin(){

return “hi ,i’am paymentzipkin server fall back,welcome to atguigu,O(∩_∩)O哈哈~”;

}

3、服务消费者(调用方)


(1)cloud-consumer-order80

(2)POM

同上

(3)YML

server:

port: 80

spring:

application:

name: cloud-order-service

zipkin:

base-url: http://localhost:9411

sleuth:

sampler:

probability: 1

eureka:

client:

#表示是否将自己注册进EurekaServer默认为true。

register-with-eureka: true

#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡

fetchRegistry: tru

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》

【docs.qq/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享

e

service-url:

#defaultZone: http://eureka7001:7001/eureka/,http://eureka7002:7002/eureka/

defaultZone: http://eureka7001:7001/eureka

(4)业务类OrderController

// ====================> zipkin+sleuth

@GetMapping("/consumer/payment/zipkin")

public String paymentZipkin(){

String result = restTemplate.getForObject(“http://localhost:8001”+"/payment/zipkin/", String.class);

return result;

}

更多推荐

SpringCloud Sleuth分布式请求链路跟踪,java运维工程师面试题

本文发布于:2023-04-07 03:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/647559e4b2add8dae3de45311634ce97.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分布式   链路   面试题   工程师   SpringCloud

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 51934文章数
  • 14阅读数
  • 0评论数