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

泪湿孤枕 提交于 2019-12-09 13:37:09

问题


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!


回答1:


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());


来源:https://stackoverflow.com/questions/39957791/is-it-possible-to-subscribe-to-the-circuitbreaker-opening-event-in-hystrix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!