DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Component Tests for Spring Cloud Microservices
  • A Robust Distributed Payment Network With Enchanted Audit Functionality - Part 2: Spring Boot, Axon, and Implementation
  • 7 Microservices Best Practices for Developers

Trending

  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  • Why We Chose Iceberg Over Delta After Evaluating Both at Scale
  • LLM Integration in Enterprise Applications: A Practical Guide
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Cloud Sleuth + RabbitMQ + Zipkin + ElasticSearch

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.

By 
Ken Jianning Liao user avatar
Ken Jianning Liao
·
Updated Aug. 30, 21 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
15.5K Views

Join the DZone community and get the full member experience.

Join For Free

Infographic.

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:

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:

Properties files
 




xxxxxxxxxx
1


 
1
spring.rabbitmq.addresses={rabbitmq_host}:5672
2
spring.rabbitmq.virtual-host: app_vhost
3
spring.rabbitmq.username=username
4
spring.rabbitmq.password=password
5
...



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 

OR 

Kafka: Sleuth with Zipkin:

Properties files
 




xxxxxxxxxx
1


 
1
spring.zipkin.sender.type=rabbit
2
spring.zipkin.rabbitmq.queue=zipkin
3
....



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:

XML
 




xxxxxxxxxx
1
58


 
1
version: '3.7'
2
services:
3
  zipkin:
4
    image: openzipkin/zipkin
5
    deploy:
6
      replicas: 1
7
      update_config:
8
        parallelism: 1
9
        delay: 1m30s
10
        failure_action: rollback
11
      rollback_config:
12
        parallelism: 1
13
        delay: 1m30s
14
      restart_policy:
15
        condition: on-failure
16
        delay: 5s
17
        max_attempts: 3
18
      resources:
19
        limits:
20
          memory: 500M
21
        reservations:
22
          memory: 100M
23
    ports:
24
      - 9411:9411
25
    environment:
26
      RABBIT_CONCURRENCY: 1
27
      RABBIT_CONCURRENCY: 1
28
      RABBIT_CONNECTION_TIMEOUT: 60000
29
      RABBIT_QUEUE: zipkin
30
      RABBIT_ADDRESSES: {rabbitmq_host}:5672
31
      RABBIT_PASSWORD: password
32
      RABBIT_USER: user
33
      RABBIT_VIRTUAL_HOST: app_vhost
34
      RABBIT_USE_SSL: "false"
35
      STORAGE_TYPE: elasticsearch
36
      ES_HOSTS: http://{elasticsearch_host}:9200
37
      
38
    healthcheck:
39
      test: wget --no-verbose --tries=1 --spider http://localhost:9411/health  || exit 1
40
      interval: 10s
41
      start_period: 15s
42
      retries: 3
43

          
44
  zipkin-dependencies:
45
    image: openzipkin/zipkin-dependencies
46
    deploy:
47
      replicas: 1
48
      restart_policy:
49
        delay: 1h
50
      resources:
51
        limits:
52
          memory: 550M
53
        reservations:
54
          memory: 100M
55
    environment:
56
      STORAGE_TYPE: elasticsearch
57
      ES_HOSTS: http://{elasticsearch_host}:9200



It fetches the Sleuth messages from RabbitMQ and stores the data in ElasticSearch. Check the ES indices.health status

Deploy the services in Docker Host, and access it with this URL.

Trace logs:
Trace logs screenshot.


Service Dependencies:

Service dependencies screenshot.

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”:

Shell
 




xxxxxxxxxx
1
15


 
1
curl -X PUT "http://$ES_HOST:9200/_ilm/policy/zipkin-cleanup_policy?pretty" \
2
     -H 'Content-Type: application/json' \
3
     -d '{
4
      "policy": {
5
        "phases": {
6
          "hot": {
7
            "actions": {}
8
          },
9
          "delete": {
10
            "min_age": "180d",
11
            "actions": { "delete": {} }
12
          }
13
        }
14
      }
15
    }'



Create the Index template with the “Zipkin-cleanup_policy.”

Shell
 




xxxxxxxxxx
1


 
1
curl -X PUT "http://$ES_HOST:9200/_template/zipkinidx_template" \
2
        -H 'Content-Type: application/json' \
3
        -d ' {
4
       "index_patterns": ["zipkin*"],
5
       "settings": {"number_of_shards": 1, "number_of_replicas": 1,
6
                            "index.lifecycle.name": "zipkin-cleanup_policy"
7
                          }
8
    }'



Apply the “Zipkin-cleanup_policy” to existing indices:

Shell
 




xxxxxxxxxx
1


 
1
curl -X PUT "http://$ES_HOST:9200/zipkin*/_settings?pretty" \
2
        -H 'Content-Type: application/json' \
3
        -d '{ "lifecycle.name": "zipkin-cleanup_policy" }'



Check out more details on this page: Spring Cloud Sleuth.

Spring Cloud Spring Framework Elasticsearch

Opinions expressed by DZone contributors are their own.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Component Tests for Spring Cloud Microservices
  • A Robust Distributed Payment Network With Enchanted Audit Functionality - Part 2: Spring Boot, Axon, and Implementation
  • 7 Microservices Best Practices for Developers

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook