Circuit Breaker www.thoughts-on-java.org
• Handle unavailable / unresponsive services Circuit Breaker • Stop if X requests failed • Goals • Don‘t block local resource • Don‘t overload unresponsive services • Provide fallbacks www.thoughts-on-java.org
Spring Cloud Hystrix • Based on Netflix Hystrix • https://github.com/Netflix/hystrix • Spring Cloud Starter • spring-cloud-starter-hystrix www.thoughts-on-java.org
Spring Cloud Hystrix • @EnableCircuitBreaker on configuration class • @HystrixCommand on method • Works within a @Service or @Component • Don‘t call internally www.thoughts-on-java.org
Code Samples www.thoughts-on-java.org
Hystrix Configuration www.thoughts-on-java.org
Hystrix Configuration • Hystrix configuration • https://github.com/Netflix/Hystrix/wiki/Configuration • Set via • @HystrixProperty annotations • External configuration www.thoughts-on-java.org
• execution.isolation.thread.timeoutInMilliseconds Hystrix Property • Timeout in ms for command execution • Default: 1000 www.thoughts-on-java.org
• circuitBreaker.requestVolumeThreshold Hystrix Property • Minimum number of requests to trip the circuit • Default: 20 www.thoughts-on-java.org
• circuitBreaker.errorThresholdPercentage Hystrix Property • Error percentage that trips the circuit • Default: 50 www.thoughts-on-java.org
• circuitBreaker.sleepWindowInMilliseconds Hystrix Property • Time until new attempt • Default: 5000 www.thoughts-on-java.org
• Add commandProperties to @HystrixCommand Annotation-based • Array of @HystrixProperty www.thoughts-on-java.org
Code Samples www.thoughts-on-java.org
• Define commandKey for @HystrixCommand File-based www.thoughts-on-java.org
• Same as annotation-based • Requires prefix File-based • hystrix.command.<CommandKey>.<ParamName> www.thoughts-on-java.org
Code Samples www.thoughts-on-java.org
• Handle unavailable / unresponsive services • Release local resources Summary • Don‘t overload other services • Avoid cascading effects • Provide fallbacks www.thoughts-on-java.org
Recommend
More recommend