1.

What is Hystrix?

Answer»

HYSTRIX is Netflix implementation for CIRCUIT breaker pattern, that ALSO employs bulkhead design pattern by operating each circuit breaker within its own thread pool. It also collects many useful metrics about the circuit breaker’s internal state, including -

  1. Traffic volume.
  2. Request volume.
  3. Error percentage.
  4. Hosts reporting
  5. Latency percentiles.
  6. Successes, failures, and rejections.

All these metrics can be aggregated using another Netflix OSS project called Turbine. Hystrix dashboard can be used to VISUALIZE these aggregated metrics, providing excellent visibility into the overall health of the distributed system.
Hystrix can be used to specify the fallback method for execution in case the ACTUAL method call fails. This can be useful for graceful degradation of functionality in case of failure in remote invocation. 

Add hystrix library to build.gradle dependencies {  compile('org.springframework.cloud:spring-cloud-starter-hystrix')

1) Enable Circuit Breaker in main application 

@EnableCircuitBreaker @RestController @SpringBootApplication public class ReadingApplication { ... }

2) Using HystrixCommand fallback method execution 

@HystrixCommand(fallbackMethod = "reliable")  public String readingList() { URI uri = URI.create("http://localhost:8090/recommended"); return this.restTemplate.getForObject(uri, String.class);  }  public String reliable() { 2 return "Cached recommended response";  }
  1. Using @HystrixCommand annotation, we specify the fallback method to execute in case of exception. 
  2. fallback method should have the same signature (return type) as that of the original method. This method provides a graceful fallback behavior while the circuit is in the open or half-open state.


Discussion

No Comment Found