For unit testing I would like to be able to subscribe to Hystrix events, particularly should there be an event when a circuit breaker opens or closes. I looked around for examples and it appears that the work around is to tap into the metrics stream and monitor the circuit breaker flags.
Since Hystrix is build on RxJava I thought there should be a subscription interface for events somewhere. Is there an easy way to subscribe to these type of events in Hystrix?
Thank you!
You need to write Custom event notifier and registered it in HystrixPlugins. have look on below code.
public class CircuitBreakerHystrixEventNotifier extends HystrixEventNotifier{
public CircuitBreakerHystrixEventNotifier(){
}
public void markEvent(HystrixEventType eventType, HystrixCommandKey key) {
//here write code based on eventTypes.
}
}
You need to registered this CircuitBreakerHystrixEventNotifier in hystrix, see below
HystrixPlugins.getInstance().registerEventNotifier(getCircuitBreakerHystrixEventNotifier());
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