如题:根据HystrixDashboard查看熔断状态为Closed,
按理说应该不会调用熔断方法,但看返回结果并非如此。
下面来看看我是怎么做的
开发环境:springboot-2.1.7.release
导入如下依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
添加hystrix配置类
测试代码
ExceptionHystrix中编写了一个API /exception/{i},(根据i的值决定方法走向)
在此方法上添加了hystrix配置,
我的预想是在满足配置的情况下才会调用熔断方法OnError(),否则抛出异常
i是2的倍数,throw Exception,否则调用熔断方法
开始测试
浏览器输入localhost:8888/hystrix/exceprion/1,测试i=1,必定会throw Exception,我的hystrix配置有一条是:
name = "circuitBreaker.requestVolumeThreshold", value = "3"
我理解至少执行三次才有可能触发熔断,以下是我调用一次接口:
此时观察HystrixDashboard如下:
也就是说还没达到熔断条件,已经调用熔断方法了,大家知道是怎么回事吗?