1:方法的熔断
/** * 服务熔断 * * @return */ @HystrixCommand(fallbackMethod = "numLessZeroException", commandProperties = { //ctrl+shift+A 查询HystrixCommandProperties @HystrixProperty(name = "circuitBreaker.enabled", value = "true"), //是否开启断路器 @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"), //请求次数 @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"), //时间窗口期 @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60") //失败率达到多少后跳闸 }) public String paymentInfo_service_fusing(Integer id) { if (id == null || id < 0) { throw new RuntimeException("id 不能小于0"); } return Thread.currentThread().getName() + " " + "调用成功,流水号:" + id; }
2:注解
@EnableEurekaClient @SpringBootApplication @EnableCircuitBreaker //启动hystrix熔断 @EnableHystrixDashboard //开启图形化界面 public class HystrixPaytment8001 { public static void main(String[] args) { SpringApplication.run(HystrixPaytment8001.class); } }
@EnableCircuitBreaker //启动hystrix熔断