简体   繁体   English

Hystrix 断路器在 Spring Micro 服务实现中触发一个事件

[英]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).有没有一种方法可以识别 Hystrix 何时从电路打开状态变为半打开状态(在睡眠时间间隔之后)。 Can Hystrix trigger an event when this state change happen?当这种状态发生变化时,Hystrix 可以触发事件吗? Any Hystrix property can tell us this?任何 Hystrix 属性都可以告诉我们这一点吗? 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 没有办法通知用户状态变化。 Hystrix provides some variables in event notifier but it doesn't contain events pertaining to state( HALF_OPEN or CLOSE). Hystrix 在事件通知器中提供了一些变量,但它不包含与状态(HALF_OPEN 或 CLOSE)有关的事件。

What one can do is create a mechanism that calls continuously or with delay to check the state of hystrix command.可以做的是创建一种机制,连续或延迟调用以检查 hystrix 命令的状态。 The hystrix instance can be fetched by:可以通过以下方式获取 hystrix 实例:

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.所以你的服务可以使用这些返回的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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