Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it Possible to Subscribe to the CircuitBreaker Opening Event in Hystrix?

Tags:

java

hystrix

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!

like image 571
Toaster Avatar asked Mar 10 '23 22:03

Toaster


1 Answers

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());
like image 195
Rakesh Avatar answered Apr 27 '23 22:04

Rakesh