第一次使用Hystrix实现服务降级,使用了
@HystrixCommand(fallbackMethod = "fallback")
@GetMapping("/getProductList213")
public String getProductList(){
RestTemplate restTemplate = new RestTemplate();
return restTemplate.postForObject("http://localhost:8082/product/listForOrder",
Arrays.asList("157875227953464068"),String.class);
}
private String fallback(){
return "太拥挤啦,请稍后再试";
}
private String defaultFallback(){
return "太太拥挤啦,请稍后再试";
}
发现调用结果没有提示拥挤,经过查看源码发现,hystrix服务降级的定义最低时间是1秒,请求时间在1秒内,则不钓鱼哦那个fallbacl