2016-11-06 336 views
0

我正在测试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?

在此先感谢...

回答

-1

请求threashold量是controling并发theads的数量可以被允许执行。