简体   繁体   中英

Hystrix circuit breaker trigger an Event in Spring Micro service implementation

Is there a way we can identify when the Hystrix moves from circuit open to half open state (after sleep time interval). Can Hystrix trigger an event when this state change happen? Any Hystrix property can tell us this? If it can trigger an event, please tell the approach. Any code examples also will be helpful.

Thanks, Nikhil

There is no approach by which hystrix will notify the user about state change. Hystrix provides some variables in event notifier but it doesn't contain events pertaining to state( HALF_OPEN or CLOSE).

What one can do is create a mechanism that calls continuously or with delay to check the state of hystrix command. The hystrix instance can be fetched by:

HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(HystrixCommandKey.Factory.asKey(name));

and post this we do respective functions to check the state of the circuitBreaker like :

circuitBreaker!=null, circuitBreaker.allowRequest(), circuitBreaker.isOpen();

So your service can use the state returned by these.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM