0% found this document useful (0 votes)
94 views4 pages

LAB-Using Hystrix As Circuit Breaker: in This Lab, You Will Be Working On Projects Under 05-Hystrix Working Set

This document discusses using Hystrix as a circuit breaker in a microservices application. It provides steps to: 1. Configure Hystrix in two microservices (cargo-booking and cargo-routing services) to add fallback logic that returns a cargo itinerary with zero legs when the routing service call fails. 2. View the Hystrix dashboard at port 5555 to monitor circuit statuses and thread pools of both services after they are made Hystrix-enabled. 3. The dashboard can monitor individual service streams as well as a combined turbine stream that aggregates data from both services.

Uploaded by

Alper Yilmaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views4 pages

LAB-Using Hystrix As Circuit Breaker: in This Lab, You Will Be Working On Projects Under 05-Hystrix Working Set

This document discusses using Hystrix as a circuit breaker in a microservices application. It provides steps to: 1. Configure Hystrix in two microservices (cargo-booking and cargo-routing services) to add fallback logic that returns a cargo itinerary with zero legs when the routing service call fails. 2. View the Hystrix dashboard at port 5555 to monitor circuit statuses and thread pools of both services after they are made Hystrix-enabled. 3. The dashboard can monitor individual service streams as well as a combined turbine stream that aggregates data from both services.

Uploaded by

Alper Yilmaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

LAB- Using Hystrix as Circuit Breaker

In this lab, you will be working on projects under 05-hystrix working set.

In Boot dashboard, Start 04-01-eureka-server and Start 06-01-cargo-booking-hystrix-start

Open eureka web ui at http://localhost:5001 and observe that booking-service is registered in


Eureka

Open swagger ui at http://localhost:8081/swagger-ui.html

Like in earlier lab exercise, make a cargo booking and make a note of bookingId in response.

Use the below Json while making cargo booking:

{
"bookingAmount": 100,
"originLocation": "BLR",
"destLocation" : "DEL",
"destArrivalDeadline" : "2020-01-28"
}

Now make a request to route cargo from swagger ui using the bookingId

You should get 500 status code and error message because routing-service is not started.

We want fallback logic to be executed if the call to microservice fails.

We can use hystrix to achieve this behaviour.

Open pom.xml of 06-01-cargo-booking-hystrix-start and complete TODO-1

Open CargoBookingApplication.java and complete TODO-2

Complete TODO-3 in CargoRoutingServiceImpl.java to enable hystrix command.

Observe that the fallback logic in CargoRoutingServiceImple.findOptimalRouteFallback() is


returning CargoIterinary with zero legs

Open CargoBookingCommandService.java and observe assignRouteToCargo() is throwing


runtime exception if CargoIterinary is having zero legs.
Open CargoRoutingController.java and Observe routeCargo method is returning a ResponseEntity
with status code 503 if exception is thrown from CargoBookingCommandService.
assignRouteToCargo()

Now restart the 06-01-cargo-booking-hystrix-start .

Open swagger ui at http://localhost:8081/swagger-ui.html

Like in earlier lab exercise, make a cargo booking and make a note of bookingId in response.

Use the below Json while making cargo booking:

{
"bookingAmount": 100,
"originLocation": "BLR",
"destLocation" : "DEL",
"destArrivalDeadline" : "2020-01-28"
}

Now make a request to route cargo from swagger ui using the bookingId

You should get 503 status code and error message as shown below:

How Does Hystrix Work?

See the code inside HystrixCircuitBreakerConfiguration and HystrixCommandAspect

Visit the following page to see configuration parameters for Hystrix Command
https://github.com/Netflix/Hystrix/wiki/Configuration
Hystrix Dashboard

Open 06-02-hystrix-first-app and 06-03-hystrix-second-app and observe the hystrix commands in


Controller.

Both these apps are hystrix enabled apps

Now you will be working on 06-01-hystrixdashboard project

Configure Following dependency in pom.xml

Open pom.xml and observe that we have already added hystrix dashboard and turbine dependency.

Open HystrixDashboard.java in 06-01-hystrixdashboard project and complete TODO-1 to enable


hystrix dashboard.

Complete TODO-2 to enable turbine

Open application.yml under src/main/resources and observe that the serverport is configured as
5555.

Also observe the turbine configuration in application.yml

Run HystrixDashboard.java .

Now open http://localhost:5555/hystrix in browser

In the text box , give the url as http://localhost:8080/actuator/hystrix.stream and click on


Monitor Stream.

You should see Circuit status for all the Hystrix commands and Thread pool status of first app

Can you make the circuit to open ?

What are the number of failures which will open the circuit?

In hystrix dashboard , give the url as http://localhost:8081/actuator/hystrix.stream and click on


Monitor Stream.

You should see Circuit status for all the Hystrix commands and Thread pool status of first app

In hystrix dashboard, give url as http://localhost:5555/turbine.stream and observe the circuit


status and thread pool status of both the apps
Congratulations!! You know how to use Hystrix and Hystrix
Dashboard and turbine stream

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy