Spring Cloud config feign fallback(CircuitBreaker) 规则
Spring Cloud config feign fallback(CircuitBreaker) rule
现在我在hystrix中使用feign,发现当fallback方法在5s内调用20次时,Circuit会变成Open状态。我怎样才能改变这个规则。例如,让回退方法在5s内调用50次,或者通过回退回调率,让Circuit状态变为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;
}
}
}
这里描述配置参数https://github.com/Netflix/Hystrix/wiki/Configuration
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds
更改您看到的 5 秒 window。
hystrix.command.default.circuitBreaker.requestVolumeThreshold
默认为 20 个请求。
现在我在hystrix中使用feign,发现当fallback方法在5s内调用20次时,Circuit会变成Open状态。我怎样才能改变这个规则。例如,让回退方法在5s内调用50次,或者通过回退回调率,让Circuit状态变为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;
}
}
}
这里描述配置参数https://github.com/Netflix/Hystrix/wiki/Configuration
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds
更改您看到的 5 秒 window。
hystrix.command.default.circuitBreaker.requestVolumeThreshold
默认为 20 个请求。