本文主要是介绍Java17 --- SpringCloud之Zipkin链路追踪,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
一、下载zipkin及运行
二、在父工程中引入pom依赖
三、在子工程8001引入相关pom依赖
3.1、修改yml配置文件
3.2、测试代码
四、在子工程80引入相关pom依赖
4.1、修改yml配置文件
4.2、测试代码
五、测试结果
一、下载zipkin及运行
运行控制台访问地址:http://localhost:9411/zipkin/
二、在父工程中引入pom依赖
<micrometer-tracing.version>1.2.0</micrometer-tracing.version><micrometer-observation.version>1.12.0</micrometer-observation.version><feign-micrometer.version>12.5</feign-micrometer.version><zipkin-reporter-brave.version>2.17.0</zipkin-reporter-brave.version><!--micrometer-tracing-bom导入链路追踪版本中心 1--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-tracing-bom</artifactId><version>${micrometer-tracing.version}</version><type>pom</type><scope>import</scope></dependency><!--micrometer-tracing指标追踪 2--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-tracing</artifactId><version>${micrometer-tracing.version}</version></dependency><!--micrometer-tracing-bridge-brave适配zipkin的桥接包 3--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-tracing-bridge-brave</artifactId><version>${micrometer-tracing.version}</version></dependency><!--micrometer-observation 4--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-observation</artifactId><version>${micrometer-observation.version}</version></dependency><!--feign-micrometer 5--><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-micrometer</artifactId><version>${feign-micrometer.version}</version></dependency><!--zipkin-reporter-brave 6--><dependency><groupId>io.zipkin.reporter2</groupId><artifactId>zipkin-reporter-brave</artifactId><version>${zipkin-reporter-brave.version}</version></dependency>
三、在子工程8001引入相关pom依赖
<!--micrometer-tracing指标追踪 1--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-tracing</artifactId></dependency><!--micrometer-tracing-bridge-brave适配zipkin的桥接包 2--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-tracing-bridge-brave</artifactId></dependency><!--micrometer-observation 3--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-observation</artifactId></dependency><!--feign-micrometer 4--><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-micrometer</artifactId></dependency><!--zipkin-reporter-brave 5--><dependency><groupId>io.zipkin.reporter2</groupId><artifactId>zipkin-reporter-brave</artifactId></dependency>
3.1、修改yml配置文件
# ========================zipkin===================
management:zipkin:tracing:endpoint: http://localhost:9411/api/v2/spanstracing:sampling:probability: 1.0 #采样率默认为0.1(0.1就是10次只能有一次被记录下来),值越大收集越及时。
3.2、测试代码
@RestController
public class PayMicrometerController {/*** Micrometer(Sleuth)进行链路监控的例子* @param id* @return*/@GetMapping(value = "/pay/micrometer/{id}")public String myMicrometer(@PathVariable("id") Integer id){return "Hello, 欢迎到来myMicrometer inputId: "+id+" \t 服务返回:" + IdUtil.simpleUUID();}
}
远程调用接口
//链路追踪监控@GetMapping(value = "/pay/micrometer/{id}")public String myMicrometer(@PathVariable("id") Integer id);
四、在子工程80引入相关pom依赖
<!--micrometer-tracing指标追踪 1--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-tracing</artifactId></dependency><!--micrometer-tracing-bridge-brave适配zipkin的桥接包 2--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-tracing-bridge-brave</artifactId></dependency><!--micrometer-observation 3--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-observation</artifactId></dependency><!--feign-micrometer 4--><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-micrometer</artifactId></dependency><!--zipkin-reporter-brave 5--><dependency><groupId>io.zipkin.reporter2</groupId><artifactId>zipkin-reporter-brave</artifactId></dependency>
4.1、修改yml配置文件
# zipkin图形展现地址和采样率设置
management:zipkin:tracing:endpoint: http://localhost:9411/api/v2/spanstracing:sampling:probability: 1.0 #采样率默认为0.1(0.1就是10次只能有一次被记录下来),值越大收集越及时。
4.2、测试代码
@RestController
public class OrderMicrometerController {@Autowiredprivate PayFeignApi payFeignApi;@GetMapping(value = "/feign/micrometer/{id}")public String myMicrometer(@PathVariable("id") Integer id) {return payFeignApi.myMicrometer(id);}
}
五、测试结果
这篇关于Java17 --- SpringCloud之Zipkin链路追踪的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!