resilience4j / resilience4j

Resilience4j is a fault tolerance library designed for Java8 and functional programming
Apache License 2.0
9.81k stars 1.35k forks source link

CircuitBreaker should publish events as an event stream and clients should be able to subscribe #13

Closed RobWin closed 8 years ago

RobWin commented 8 years ago

A CircuitBreaker should store (a configurage number of) handled exceptions so that you can retrieve the list of exceptions which have triggered the CB. This helps in cases where you have to analyze some error.

RobWin commented 8 years ago

I think I refactor this again. The CircuitBreaker should not store exceptions itself, but publish events as a event stream. An event can be an exception (CircuitBreakerRecordedFailureEvent) or a state transition (CircuitBreakerStateTransitionEvent). A system which is interested in these events can subscribe to the event stream and store the events in a CircularBuffer itself. The CircuitBreaker is lightweight again, but extendable by using reative streams. I think I introduce RxJava to make the CircuitBreaker an Publisher. That way I don't have to implement an EventBus myself. Using Reactive Streams the events can easily be handled on a different thread pool and do not decrease the performance of the CircuitBreaker.

storozhukBM commented 8 years ago

Hi @RobWin Please consider usage of ReactiveStreams specification. With this interfaces the implementation will be meter of choice for library users [RxJava, Akka, Reactor...]. It also will be compatible with Java9's Flow

RobWin commented 8 years ago

Yes, I will just add org.reactivestreams:reactive-streams:1.0.0 as a compile dependency