Jon*_*han 12
CircuitBreaker breaker = new CircuitBreaker()
.withFailureThreshold(5)
.withSuccessThreshold(3)
.withDelay(1, TimeUnit.MINUTES);
Failsafe.with(breaker).run(() -> connect());
Run Code Online (Sandbox Code Playgroud)
没有那么简单.
Apache commons有几种类型的轻量级断路器的实现,这里是文档的链接
该项目提供了EventCountCircuitBreaker和ThresholdCircuitBreaker类,抽象的AbstractCircuitBreaker,所以你可以实现你自己的.
代码是开源的,并在github上托管,因此任何试图实现该模式的人都应该至少看一眼.
您可以在Martin Fowler 的博客中获得有关此模式的大量有用信息。它包含 ruby 实现以及其他语言实现的参考。
请检查Jrugged 库。它包含 Spring 中的 Circuit Breaker 实现以及其他设计模式。
| 归档时间: |
|
| 查看次数: |
19574 次 |
| 最近记录: |