断路器设计模式实现

use*_*494 13 java spring design-patterns

我曾尝试没有成功实现断路器的模式,这里使用Spring框架,在Java中.

如何通过Java和Spring实现断路器模式?

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)

没有那么简单.


sva*_*rog 7

Apache commons有几种类型的轻量级断路器的实现,这里是文档的链接

该项目提供了EventCountCircuitBreakerThresholdCircuitBreaker类,抽象的AbstractCircuitBreaker,所以你可以实现你自己的.

代码是开源的,并在github托管,因此任何试图实现该模式的人都应该至少看一眼.


Gui*_*ume 5

Spring cloud提供了一些与Hystrix 的有趣集成。你可能应该看看它......


Daw*_*ski 4

关于图案本身

您可以在Martin Fowler 的博客中获得有关此模式的大量有用信息。它包含 ruby​​ 实现以及其他语言实现的参考。

关于java spring的实现

请检查Jrugged 库。它包含 Spring 中的 Circuit Breaker 实现以及其他设计模式。