现在我将feign与hystrix一起使用,结果是在5秒内回退方法调用20次时,电路将变为打开状态。如何更改此规则。例如,当回退方法在5秒内调用50次或回退回调速率时,电路状态变为open。下面是我的主要java代码。
ConsumerApplication.java
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableCircuitBreaker
@RibbonClients({@RibbonClient(name = "cloud-provider", configuration = CloudProviderConfiguration.class)})
public class ConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
UserFeignClient.java
@FeignClient(name = "cloud-provider", fallback = UserFeignClient.HystrixClientFallback.class)
public interface UserFeignClient {
@RequestMapping("/{id}")
BaseResponse findByIdFeign(@RequestParam("id") Long id);
@RequestMapping("/add")
BaseResponse addUserFeign(UserVo userVo);
@Component
class HystrixClientFallback implements UserFeignClient {
private static final Logger LOGGER = LoggerFactory.getLogger(HystrixClientFallback.class);
@Override
public BaseResponse findByIdFeign(@RequestParam("id") Long id) {
BaseResponse response = new BaseResponse();
response.setMessage("disable!!!!");
return response;
}
@Override
public BaseResponse addUserFeign(UserVo userVo) {
BaseResponse response = new BaseResponse();
response.setMessage("disable");
return response;
}
}
}
发布于 2017-03-08 23:34:14
配置参数在此处https://github.com/Netflix/Hystrix/wiki/Configuration中描述
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds
会更改您看到的5秒窗口。
hystrix.command.default.circuitBreaker.requestVolumeThreshold
默认为20个请求。
https://stackoverflow.com/questions/42666887
复制相似问题