Spring Cloud Sleuth + RabbitMQ + Zipkin + ElasticSearch
As more and more microservices are deployed in the system, service dependencies are getting more complicated. Use this tutorial as a guide for you.
Join the DZone community and get the full member experience.Join For Free
Add Sleuth, RabbitMQ, and Zipkin in Spring Cloud Project
This article assumes that you know how to set up a spring cloud or spring boot project; also, the RabbitMQ and ElasticSearch servers are ready.
Add the dependencies in maven pom.xml:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-sleuth</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> <!-- <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency> --> <!--Spring Sleuth3.0 removed spring-cloud-starter-zipkin: https://docs.spring.io/spring-cloud-sleuth/docs/3.0.0-M3/reference/html/#sleuth-with-zipkin-via-http Use the following dependency instead --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin</artifactId> </dependency>
Set up the RabbitMQ properties in Spring Cloud: Common Application Properties:
Set up the Zipkin properties: Spring Cloud Sleuth Common Application Properties, set the property "spring.Zipkin.sender.type=rabbit." Sleuth can send messages to Zipkin via HTTP, RabbitMQ
Kafka: Sleuth with Zipkin:
Rebuild and restart the service; a RabbitMQ queue "Zipkin" will be created.
Setup Zipkin, Zipkin-dependencies Services With Docker Image
Docker Compose file includes Zipkin and Zipkin-dependencies services; Zipkin_RabbitMQCollector.
”Zipkin-dependencies” is a process service that combines Zipkin indices: “Zipkin-span-xxx” into “Zipkin-dependency-xx”; in the following sample docker-compose.xml, it is set to run every hour:
It fetches the Sleuth messages from RabbitMQ and stores the data in ElasticSearch. Check the ES indices.
Deploy the services in Docker Host, and access it with this URL.
Setting Up Zipkin Data Clean up Policy in ElasticSearch
To archive, the old data, set up the ElasticSearch index policy to remove the data created 180 days before.
Create the Index Lifecycle “Zipkin-cleanup_policy”:
Create the Index template with the “Zipkin-cleanup_policy.”
Apply the “Zipkin-cleanup_policy” to existing indices:
Check out more details on this page: Spring Cloud Sleuth.
Opinions expressed by DZone contributors are their own.