这篇文章主要讲解了“怎么实现Spring Cloud的服务链路追踪”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么实现Spring Cloud的服务链路追踪”吧!
一、准备工作
启动kafka服务,启动前面的 erurekaserver、config-server
二、安装zipkinServer
下载地址:
https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server/
下载完成jar 包之后,运行即可:
java -jar zipkin-server-2.9.4-exec.jar

三、修改项目eurekaclient1
1、修改bootstrap.yml,添加 spring.zipkin.base-url: http://localhost:9411,如下:
server:
port: 8762
spring:
application:
name: eurekaclient
cloud:
config:
label: master
profile: dev
discovery:
enabled: true
service-id: config-server
bus:
refresh:
enabled: true
trace:
enabled: true
kafka:
bootstrap-servers: 127.0.0.1:9092
zipkin:
base-url: http://localhost:9411
eureka:
instance:
instance-id: eurekaclient1
appname: ${spring.application.name}
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
management:
endpoints:
web:
exposure:
include: '*'
security:
enabled: false
2、修改pom.xml,添加
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
3、启动项目 eurekaclient1
四、修改项目service-ribbon
1、修改application.yml,添加spring.zipkin.base-url: http://localhost:9411,如下:
server:
port: 8764
spring:
application:
name: service-ribbon
zipkin:
base-url: http://localhost:9411
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
2、修改pom.xml,添加:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
3、启动项目
五、测试链路跟踪
1、访问 http://localhost:9411/zipkin/

2、访问http://localhost:8764/hello (多刷新几次)

3、访问http://localhost:9411/zipkin/
点击 Dependencies


感谢各位的阅读,以上就是“怎么实现Spring Cloud的服务链路追踪”的内容了,经过本文的学习后,相信大家对怎么实现Spring Cloud的服务链路追踪这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是天达云,小编将为大家推送更多相关知识点的文章,欢迎关注!