熔斷機制

@RequestMapping(value = "/ok", method = RequestMethod.GET)
@HystrixCommand(fallbackMethod = "okFallback", threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "30"), @HystrixProperty(name = "maxQueueSize", value = "100"),
@HystrixProperty(name = "queueSizeRejectionThreshold", value = "20") }, commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "100"),
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "50")app

})  
public String ok() throws Exception {  
    int l = new Random().nextInt(200);  
    LOG.info(String.format("l=%s", l));  
    TimeUnit.MILLISECONDS.sleep(l);  
    return "ok";  
}  

public String okFallback(Throwable e) {  
    System.out.println("execute okFallback!" + e.getMessage());  
    LOG.error("error", e);  
    return "fallback";  
}
相關文章
相關標籤/搜索