service hystrix-payment-order8001 增加方法
//=========服务熔断
@HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",commandProperties = {
// 表示开启服务熔断
@HystrixProperty(name = "circuitBreaker.enabled",value = "true"),
// 表示请求次数
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",value = "10"),
// 表示失败的时间范围 比如10秒内10此失败
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",value = "10000"),
// 开启服务熔断的阈值百分比
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage",value = "60"),
})
public String paymentCircuitBreaker(@PathVariable("id") Integer id)
{
if(id < 0)
{
throw new RuntimeException("******id 不能负数");
}
String serialNumber = IdUtil.simpleUUID();
return Thread.currentThread().getName()+"\t"+"调用成功,流水号: " + serialNumber;
}
public String paymentCircuitBreaker_fallback(@PathVariable("id") Integer id)
{
return "id 不能负数,请稍后再试,/(ㄒoㄒ)/~~ id: " +id;
}
增加controller测试
@GetMapping("/payment/circuit/{id}")
public String paymentCircuitBreaker(@PathVariable("id") Integer id)
{
String result = paymentService.paymentCircuitBreaker(id);
log.info("****result: "+result);
return result;
}
熔断打开:
熔断关闭 熔断关闭不会对服务进行熔断
熔断半开