Software Engineering

My part in its downfall

All the salient facts are true

Issues re Spring Cloud Netflix @EnableCircuitBreaker, @EnableHystrix

Objective

Clarify use of Spring Cloud Netflix @EnableCircuitBreaker, @EnableHystrix

Target Audience

Developers new to Spring Cloud Platform

Source Documents

Microservice Architecture
Spring Cloud
Spring Cloud Netflix
Hystrix
finagle
javaslang-circuitbreaker
@EnableHystrix
@EnableCircuitBreaker
hystrix-javanica

Summary

Two existing Spring Cloud Netflix annotations to enable the circuit breaker pattern exist. At this time the documentation is not clear as to the distinction in behaviour.

Result

Use @EnableHystrix to implement the circuit breaker pattern specifically with Hystrix on the classpath.

Use @EnableCircuitBreaker to implement the circuit breaker pattern with Hystrix or an alternative circuit breaker implementation.

Discussion

It can be confusing to encounter two annotations which at first seem to provide the same behaviour. However with a bit of digging and further analysis we may be able to uncover the rationale(see javadoc for why @EnableHystrix and @EnableCircuitBreaker ) exist.

Hystrix is an implementation of the Circuit Breaker pattern by Netflix. The @EnableHystrix annotation require a specific implementation, if Hystrix is not on the classpath it will fail.
@EnableCircuitBreaker is more general and it seems from here there is an impetus to abstract away the implementation of the CircuitBreaker pattern so that alternative implementations could be used such as finagle or javaslang-circuitbreaker (see source docs). The motivation being the dependencies pulled in by Hystrix.

It seems at this time there is a state of flux and I am unable to find the documentation for how you would use @EnableCircuitBreaker to wire in an alternative Circuit Breaker to Hystrix but it seems architecturally the existence of the @EnableCircuitBreaker allows for the evolution of the Spring Cloud.

More Details

Spring Cloud Netflix uses a Hyristrix dialect hystrix-javanica, this allows for the @HystrixCommand annotation to simplify the command pattern code as it applies to Hystrix.


Share

comments powered by Disqus