gpt4 book ai didi

spring-cloud - Spring Cloud config feign fallback(CircuitBreaker) 规则

转载 作者:行者123 更新时间:2023-12-04 00:06:18 24 4
gpt4 key购买 nike

现在我在 hystrix 中使用 feign,结果发现,当 fallback 方法在 5 秒内调用 20 次时,Circuit 将变为 Open 状态。我怎样才能改变这个规则。例如,当fallback方法在5s内调用50次时,让Circuit状态变为open,或者通过fallback回调率。这是我的主要 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 秒窗口。

hystrix.command.default.circuitBreaker.requestVolumeThreshold 默认为 20 个请求。

关于spring-cloud - Spring Cloud config feign fallback(CircuitBreaker) 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42666887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com