我正在测试Spring断路器,我忽略了"circuitBreaker.requestVolumeThreshold“参数实际上是如何works...See我的例子的要点.
@HystrixCommand(
fallbackMethod = "invokeMicroServiceFallback",
commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",
value = "30000"),
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",
value = "2"),
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",
value = "500"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds",
value = "180000")
},
threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "30"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds",
value = "180000")
})
public void invokeMicroService() {
final RestTemplate restTemplate = new RestTemplate();
final ServiceInstance serviceInstance = loadBalancer.choose("personsService");
if (serviceInstance != null) {
System.out.println("Invoking instance at URL: "+serviceInstance.getUri());
System.out.println("Result :"+
restTemplate.getForObject(serviceInstance.getUri()+"/persons",
String.class));
} else {
System.out.println("Service is down...");
throw new IllegalStateException("PersonsService is not running!");
}
}
public void invokeMicroServiceFallback() {
System.out.println("Waiting for circuit-breaker to close again...");
}如果我关闭personsService并在循环中调用invokeMicroService,那么我得到了很多输出,比如:
第一:
Invoking instance at URL: <URL at my service>;
"Waiting for circuit-breaker to close again..."过了一段时间后,我又重复了一遍:
Service is down...
"Waiting for circuit-breaker to close again..."circuitBreaker.requestVolumeThreshold在这里到底做了什么?为什么我不止两次尝试访问personsService?
提前谢谢..。
发布于 2016-11-07 14:41:00
来自wiki https://github.com/Netflix/Hystrix/wiki/Configuration#circuitBreaker.requestVolumeThreshold
circuitBreaker.requestVolumeThreshold此属性在滚动窗口中设置将触发电路的最小请求数。 例如,如果值为20,那么如果在滚动窗口(例如10秒的窗口)中只接收到19个请求,即使所有19个都失败了,电路也不会打开。
https://stackoverflow.com/questions/40454863
复制相似问题