Circuit breaker design pattern implementation Circuit breaker design pattern implementation spring spring

Circuit breaker design pattern implementation


For a simple, straightforward circuit breaker implementation, check out Failsafe. Ex:

CircuitBreaker breaker = new CircuitBreaker()  .withFailureThreshold(5)  .withSuccessThreshold(3)  .withDelay(1, TimeUnit.MINUTES);Failsafe.with(breaker).run(() -> connect());

Doesn't get much simpler.


Apache commons has some implementations for several types of lightweight circuit breakers, here's a link to the docs

The project provides the EventCountCircuitBreaker and ThresholdCircuitBreaker classes, and an abstract AbstractCircuitBreaker so you could implement your own.

The code is open sources and is hosted at github, so anyone attempting to implement the pattern should at least take a peek.


Spring cloud provides some interesting integration with Hystrix. You should probably have a look into it...