Reputation: 1971
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!
Upvotes: 4
Views: 2337
Reputation: 139
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());
Upvotes: 7