Why use Zipkin?
The previous article mainly wrote: Spring Cloud distributed log link Tracking
From the previous article can be seen in the call between services, assuming that there are now more than 10 services, then in the search for the log is cumbersome, complex, and in the view of the call will be like a spider web, the amount is too large.
At this time Zipkin can call the entire process to upgrade the link, only need to go to a place to find, you can know which step error.
Zipkin is also divided into servers and clients, the server is Zipkin, micro-service is the client.
First, set up the server Zipkin
In this service build.gradle plus Zipkin dependencies:
Compile ' io.zipkin.java:zipkin-server ' Io.zipkin.java:zipkin-autoconfigure-ui '
Here you can see that it's not part of spring.
In the APPLICATION.YML configuration:
Server: 9999Spring: application: name:zipkin-server #注册到注册中心的名字, can map IP
Configuration file is very simple
Startup class:
// indicates that Zipkin is a server @SpringBootApplication Public class Zipkinserverprodiver { publicstaticvoid main (string[] args) { Springapplication.run (zipkinserverprodiver). class , args);} }
Next, add dependencies to the client Build.gradle for the Zipkin server:
// represents the Zipkin client Compile group: ' Org.springframework.cloud ', Name: ' Spring-cloud-sleuth-zipkin '
Here's a couple of Zipkin's clients that join the dependency
Of course, in the client configuration file Application.yml, you also add the Zipkin configuration:
Spring: zipkin: base-url:http://localhost:9999 #代表字zipkin服务器地址 Sleuth: Sampler: 1.0 #0.1-1.0 is the probability of uploading data that represents the link tracking
Start Zipkin server: http://localhost:9999
See, that proves the success of the launch.
Start the project below, perform a call between microservices, and flush the Zipkin server:
Here you can see that I performed 4 times, there were 4 links, I looked up based on time, or I could find it based on the link encoding in the Console or log:
I'll take one at the console. Search:
You can see that you have found
Zipkin also has link analysis:
it can also be searched by time and link code, so we want to find out which period or precise to which is very convenient.
If you do not understand the small partners please refer to my previous blog for browsing, perhaps enlightened!
Link Tracking for the Spring Cloud distributed integrated Zipkin