Microservice Resiliency
Hystrix
https://github.com/jeffgbutler/microservice-workshop-java/
https://jeffgbutler.github.io/microservice-workshop-java/
What is Hystrix?
- Implementation of the Circuit Breaker pattern
- Created by Netflix
- Integrated into Spring with Spring Cloud Netflix
What is a Circuit Breaker?
- The circuit breaker is a wrapper over a command
- The wrapper watches for failures and will call a fallback method if there is a failure
- Once failures reach a certain threshold, the circuit will be "opened"
- When a circuit is opened, only the fallback method will be called
- The circuit breaker will periodically try the true method and if the failure rate falls
below the threshold, then the circuit will be "closed" and traffic will begin flowing to the true service
- Closed == Good
Configuring Hystrix and Feign
- Hystrix is available as a dependency in the Spring Initializr
- Hystrix is integrated with Feign...
- Add the
@EnableCircuitBreaker
annotation to a configuration class
- Set the property
feign.hystrix.enabled=true
- Add a
fallback
implementation class on the @FeignClient
annotation
The Hystrix Dashboard
- Hystrix will publish a stream of information about the state of the curcuits on the
/actuator/hystrix.stream
endpoint
- This data stream is hard for a human to consume!
- The Hystrix dashboard will consume the stream and present a friendly UI
- Netflix has stated that the Hystrix dashboard has some security vulnerabilites and should not be
exposed publicly
- PCF implements a circuit breaker dashboard in the Spring Cloud Services tile
Exercise
- Create fallback implementations for the feign clients
- Enable Hystrix
- Setup a Hystrix dashboard