I have tried unsuccessfully to implement circuit breaker pattern, here, in Java using Spring framework.
How can you implement circuit breaker pattern by Java and Spring?
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...
You can obtain a lot of useful information about this pattern at Martin Fowler's blog. It contains ruby implementation as well as references for implementation in other languages.
Please check the JRugged library. It contains the Circuit Breaker implementation in spring as well as other design patterns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With