Resilience: Hystrix Implementation
Explore the implementation of resilience in microservices using Hystrix within the Netflix stack. Understand how to apply circuit breakers, fallback methods, and monitor system health via the Hystrix dashboard and Turbine for scalable, fault-tolerant REST services.
We'll cover the following...
Implementation #
Hystrix offers an implementation of most resilience patterns as a Java library.
The Hystrix API requires command objects instead of simple method calls. These classes supplement the method call with the necessary Hystrix functionalities.
When using Hystrix with Spring Cloud, it is not necessary to implement commands. Instead, the methods are annotated with @HystrixCommand. It activates Hystrix for this method and the attributes of the annotation configure Hystrix.
The listing shows the access from the order microservice to the catalog microservice.
- Lines 5-6:
circuitBreaker.requestVolumeThresholdspecifies how many calls in a time window must cause errors for the circuit breaker to open. - Line 2: The
fallbackMethodattribute of the annotation configures the