通过sleuth,开启zipkin可通过访问localhost:9411/zipkin 开启web界面查看链路调用 trace id 就是一个服务id parent id 就是调用者的id 原始服务parent id = null 服务提供者 provider 导入依赖
<!--包含了sleuth+zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
yaml 核心配置 sleuth
spring:
application:
name: cloud-payment-service
zipkin:
base-url: http://localhost:9411
sleuth:
sampler:
#采样率值介于 0 到 1 之间,1 则表示全部采集
probability: 1
controller接口
@GetMapping("/payment/zipkin")
public String paymentZipkin()
{
return "hi ,i'am payment zipkin server fall back,welcome to atguigu,O(∩_∩)O哈哈~";
}
服务消费者 consumer pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
yaml
spring:
application:
name: cloud-order-service
zipkin:
base-url: http://localhost:9411
sleuth:
sampler:
probability: 1
测试接口
// ====================> zipkin+sleuth
@GetMapping("/consumer/payment/zipkin")
public String paymentZipkin()
{
String result = restTemplate.getForObject("http://localhost:8001"+"/payment/zipkin/", String.class);
return result;
}
按顺序开启 7001/ 8001/ 80 然后访问localhost/consumer/payment/zipkin 再访问localhost:9411/zipkin 即可查看服务调用链路
标签:sleuth,zipkin,springcloud,id,cloud,链路,payment,localhost From: https://www.cnblogs.com/huoziqi/p/17538463.html