If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.
Join my czetsuya tech community site to Get Answers to Questions about programming, home-based work, anything about tech and to connect and share information.
In this architecture, we have several microservices that communicate with each other to perform a single task, such as the get product stock service in the business API. This is a 2 level deep request that pulls and joins data from the catalog and inventory microservice.
This kind of architecture introduces some challenges such as log tracing across multiple microservices with each service running several instances as well as the latency between each request hop. This is where Spring Cloud Sleuth comes in, by adding metadata such as ID in the request header.
These logs are aggregated using Spring Zipkin which makes debugging easier.
2 Types of ID
Trace ID - It adds a unique ID whenever a new request is initiated plus it contains a set of span IDs. Its value does not change across microservices.
Span ID - It represents a basic unit of work such as fetching a record from a database.
How to add Zipkin to our Projects
Add spring-cloud-starter-zipkin dependency to all the projects that we want to trace.
Add the following properties to the microservies that we want to trace
spring.zipkin.baseUrl
spring.zipkin.discovery-client-enabled=false
spring.sleuth.sampler.probability=100, it means all spans will be sent to Zipkin server
Run the Applications
Run the microservices in this order:
terawarehouse-config-server (node1)
terawarehouse-service-discovery (node1)
terawarehouse-load-balancer (node1)
terawarehouse-catalog (node2)
terawarehouse-inventory (node2)
terawarehouse-business-api (node2)
How to Run Zipkin with Docker
You must have docker installed
>docker run -d -p 9411:9411 openzipkin/zipkin
Trace the Logs
In node2 open the Zipkin URL: :9411
Run the postman collection inside the src/test/resources folder in terawarehouse-catalog project.
Are you looking for freelancers in the Philippines? Get in touch.
Donations
If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.
If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.
Post a Comment