Resilience: Hystrix Implementation
In this lesson, we'll study how Hystrix is used in code.
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.
Press + to interact
@HystrixCommand(fallbackMethod = "getItemsCache",commandProperties = {@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",value = "2") })public Collection<Item> findAll() {...this.itemsCache = pagedResources.getContent();...return itemsCache;}
The listing shows the access from the order microservice to the catalog microservice. ...