Spring Cloud Sleuth+ Zipkin link tracing

Spring Cloud Sleuth’s main function is to provide tracking solutions in distributed systems, and it is compatible with Zipkin support. You just need to introduce the corresponding dependencies in the POM file.

In microservice architecture, services are divided by services. Through REST invocation, an interface exposed to the outside may require the cooperation of many services to complete the interface function. If any service on the link fails or the network times out, the interface invocation will fail. As businesses expand, services call each other more and more complex.

This section explains how to use Sleuth and Zipkin to build link tracing for microservices.

Download Zipkin Server and start it

Download the following address and start:

curl -sSL https://zipkin.io/quickstart.sh | bash -s
java -jar zipkin.jar

Copy the code

Access zipkin’s UI at localhost:9411

The reconstruction project

Add the following dependencies to the three project provider consumer Gateway POM files:

         <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin</artifactId>
        </dependency>
Copy the code

The three project profiles, application.yml, add the following configuration:

Spring. Zipkin. Sender. Type: web # set the sample rate by default to pay attention to the previous version 0.1 is replaced in the percentage with the new version for aim-listed probability spring. The sleuth. Sampler. The aim-listed probability: 1 spring.zipkin.base-url: http://localhost:9411/ spring.zipkin.service.name: consumerCopy the code

Zipkin Server supports mq link information collection and multiple data storage methods, such as ES \mysql. For more data collection and storage methods, see github.com/openzipkin/…

Start the three project, on the browser to visit: http://localhost:5000/consumer/hi-feign

Accessing the Zipkin Server API, you can see the service dependencies as follows:

You can see how long the request takes:

Reference documentation

Zipkin. IO/pages/quick…

www.fangzhipeng.com/springcloud…

Download the source code

Github.com/forezp/Spri…