我正在測試Spring Cloud斷路器,並且我缺少實際上「circuitBreaker.requestVolumeThreshold」參數實際工作的點...請參閱我的示例...circuitBreaker.requestVolumeThreshold不能正常工作
@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..."
再經過一段時間,J ust重複:
Service is down...
"Waiting for circuit-breaker to close again..."
什麼circuitBreaker.requestVolumeThreshold實際上在這裏做? 爲什麼我有兩次嘗試訪問personsService?
在此先感謝...