服务提供方死机或者请求太太超出自己承受范围,则熔断
注解实现:基于Hystrix,访问传入负数则报错,当10次有2次出错则断开,并保持一段时间逐渐恢复。
//===================熔断======================
@GetMapping("/paymentfireCut/{id}")
@HystrixCommand(fallbackMethod = "paymentInfo_timeout_handler",commandProperties = {
@HystrixProperty(name="circuitBreaker.enabled",value = "true"),//是否开启断路器
@HystrixProperty(name="circuitBreaker.requestVolumeThreshold",value = "10"),//请求次数
@HystrixProperty(name="circuitBreaker.sleepWindowInMilliseconds",value = "10000"),//时间范围
@HystrixProperty(name="circuitBreaker.errorThresholdPercentage",value = "20"),//失败率达到多少后跳闸
})
public String payentfireCut(@PathVariable("id") Integer id){
if(id<0){
throw new RuntimeException();
}else{
String s = IdUtil.simpleUUID();
return s;
}
}
hystrix实现了链路自动恢复功能。