Reprinted Disclaimer: The source of the article is to carry sacks of teenager
Contents of this article:
Write at the beginning
Continued from the previous article: Spring Cloud Stream message driver . Mastered it Spring Cloud Stream
to make the communication between MQ more convenient. Here we come to learn another new components: Spring Cloud Sleuth 分布式链路追踪
.
1. The origin of Spring Cloud Sleuth
Direct plane ticket: Spring Cloud Sleuth official website
In the microservice framework, a request initiated by the client will be called by multiple different microservice nodes in the back-end system, and coordinated operations to produce the final request result. Each request will form the front end of a complex distributed service call link, any link in a ring should appear 高延时
or 错误
will cause final failure of the entire request.
Spring Cloud Sleuth 提供了分布式系统中一套完整的服务跟踪的解决方案,并且兼容支持了zipkin,完美的解决了多个微服务之间链路调用的问题。
One sentence summary: It is used to handle the calling relationship between services.
2. Call structure diagram
3. Environmental preparation
Zipkin is an open source project of Twitter that allows developers to collect monitoring data on various Twitter services and provide query interfaces.
We need to prepare a Zipkin environment first. Spring Cloud 从F版起已不需要自己构建 Zipkin server了,只需要调用jar包即可
. The currently used version is version H. We only need to download Zipkin jar package, use java -jar xxx
way to start.
Click on the link: https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server and download it zipkin-server-2.12.9-exec.jar
. The startup is OK, as shown in the figure.
You can enter the visual interface provided by Zipkin through http://loclahost:9411. It has a fresh look, especially the Chinese interface. I really love it.
4. Sleuth test environment construction
This test uses the existing environment before. In the 客户端(80)
call to 服务端(8001)
service, service call using the provided openFeign
way. I won’t introduce the code too much here, please download it from the link at the end of the article.
❤ server / client the same configuration
Ⅰ. Both need to introduce zipkin + sleuth pom dependency
<!--引入sleuth+zipkin依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
Ⅱ. Both need to add the same configuration of zipkin and sleuth in applicaiton.yml
spring:
# 应用名
application:
name: cloud-payment-service
zipkin:
base-url: http://localhost:9411 #监控数据要打到9411zipkin上
sleuth:
sampler:
probability: 1 #采样率值介于0到1,1则表示全部采集
Ⅲ. The configuration has come to an end, please check the specific business download code
Is a simple micro-service call process, 客户端
call the 服务端
service provided.
Ⅳ. Microservice service call test
Through the http://localhost/consumer/payment/get/31
service call, after the call is successful, we http://localhost:9411
can see the specific service call status by opening the Zipkin console.
Click the corresponding request, you can also see 模块间调用情况
and 调用耗时
wait for more detailed information. Click the navigation bar 依赖
items, you can also view the dependencies module (call is being made), etc., link to call the relationship a glance. It smells so good! ! !
The code download address of this article: Spring Cloud Sleuth distributed link tracking, the calling link is clearer (extraction code: zw97)
Spring Cloud Sleuth
Relatively simple, the length is not long, nothing to say, is a link tracking tool, deeper content, please skip the official website to understand. Next is a new chapter.