下面是我的 Hystrix 命令配置:
@HystrixCommand(fallbackMethod = "fall", commandProperties = {
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "5"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "10000") })
public <T> T getInfo(Class clazz) {....}
回退方法:
public <T> T fall(Class clazz) {
System.out.println("fallback");
throw new CustomRuntimeException("API Down");
}
我了解根据以下配置,即
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "5"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "10000") }
5 个请求将在 10 秒内被允许,直到电路跳闸打开并且来自第 5 个请求的每个请求都将被拒绝,并且由于我在后备方法中抛出异常,它将被包装为HystrixRuntimeException
.
但我面临以下问题:
- 直到电路跳闸打开,回退正常执行并抛出
CustomRuntimeException
(注意:Hystrix Command 方法也抛出CustomRuntimeException
) - 电路跳闸打开后,我得到
Caused by: com.netflix.hystrix.exception.HystrixRuntimeException: getInfo short-circuited and fallback failed.
问题:
- 为什么在电路打开之前异常没有包装为 HystrixRuntimeException 即当前回退正常执行并抛出 CustomRuntimeException 直到电路打开?*
- 为什么在流程 1->2->3->4->5->6->8 中,即使在失败(即 Throwing
CustomRuntimeException
)之后执行回退方法并且不会抛出 WrappedHystrixRuntimeException
,这发生在流程 1 的情况下->2->3->4->8 和 1->2->3->5->8