Spring Cloud Sleuth + Zipkin distributed link tracking, link calls are clearer

Reprinted Disclaimer: The source of the article is to carry sacks of teenager


Write at the beginning

  Continued from the previous article: Spring Cloud Stream message driver . Mastered it Spring Cloud Streamto 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

Insert picture description here

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 xxxway 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.
Insert picture description here
  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.
Insert picture description here

4. Sleuth test environment construction

  This test uses the existing environment before. In the 客户端(80)call to 服务端(8001)service, service call using the provided openFeignway. 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/31service call, after the call is successful, we http://localhost:9411can 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! ! !
Insert picture description here
The code download address of this article: Spring Cloud Sleuth distributed link tracking, the calling link is clearer (extraction code: zw97)

  Spring Cloud SleuthRelatively 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.

Next: Spring Cloud Alibaba joins the Spring Cloud system

Guess you like

Origin blog.csdn.net/m0_37989980/article/details/108572422