Spring boot 如何为@FeignClient正确配置回退和重试程序?

Spring boot 如何为@FeignClient正确配置回退和重试程序?,spring-boot,hystrix,spring-cloud-feign,fallback,feign,Spring Boot,Hystrix,Spring Cloud Feign,Fallback,Feign,我在为外部客户端配置回退时遇到问题。假设我有这样的客户: @FeignClient(name=“some client”,url=“${some client.url}”) 公共接口客户端{ @GetMapping(value=“/api/some endpoint”,products=MediaType.APPLICATION\u JSON\u value) 列出searchForAllDtos(@RequestParam(“param”)字符串param); } 我已将simple ret

我在为外部客户端配置回退时遇到问题。假设我有这样的客户:

@FeignClient(name=“some client”,url=“${some client.url}”)
公共接口客户端{
@GetMapping(value=“/api/some endpoint”,products=MediaType.APPLICATION\u JSON\u value)
列出searchForAllDtos(@RequestParam(“param”)字符串param);
}
我已将simple retryer配置为:

@配置
公共类客户端配置{
@豆子
public Retryer Retryer(@Value(${http.retry.period})长周期,
@值(${http.retry.maxPeriod})长maxPeriod,
@值(${http.retry.maxAttempts})int-maxAttempts){
返回新的CustomRetryer(期间、最大期间、最大尝试次数);
}
@豆子
公共错误解码器(){
返回新的CustomDecoder();
}
}
@Slf4j
类CustomRetryer扩展了Retryer.Default{
私人决赛;
私人最终长期;
私人最终长周期;
公共CustomRetryer(长周期、长最大周期、整数最大尝试){
超级(周期、最大周期、最大尝试次数);
这个周期=周期;
this.maxPeriod=maxPeriod;
this.maxAttempts=maxAttempts;
}
私人客户经理(客户经理){
super(retryer.period、retryer.maxPeriod、retryer.maxtruments);
this.period=retryer.period;
this.maxPeriod=retryer.maxPeriod;
this.maxtures=retryer.maxtures;
}
@凌驾
公共void continueOrPropagate(RetryableException ex){
超级连续复制门(ex);
log.warn(“重试HTTP请求…”);
}
@凌驾
公共检索器克隆(){
返回新的CustomRetryer(此);
}
}
类CustomDecoder实现ErrorDecoder{
公共异常解码(字符串方法键、响应){
if(response.status()>499){
抛出新的RetryableException(
response.status(),
String.format(“服务不可用(状态代码%s)”,response.status(),
response.request().httpMethod(),
无效的
response.request());
}否则{
返回新的运行时异常(
String.format(“HTTP请求后收到状态代码%s的错误”,response.status());
}
}
}
在配置最大尝试次数后,当调用仍然失败时,我想添加回退,在此之前,一切都很好。我改变了我的客户如下:

@FeignClient(name=“some client”,url=“${some client.url}”,fallback=SomeClientFallback.class)
公共接口客户端{
//等等。
}
@组成部分
类SomeClientFallback实现SomeClient{
@凌驾
AllDTOS的公共列表搜索(字符串参数){
返回集合。emptyList();
}
}
它不起作用,异常仍然被抛出,而不是路由到回调,我已经读到必须启用hystrix,所以我已经将
feign.hystrix.enabled=true
添加到我的application.properties文件中。在调查和编写一些测试之后,我发现重试只有在配置为最多5次尝试时才使用一次。看起来与默认设置为1000ms的hystrix timeout存在一些冲突。我曾尝试通过
hystrix.command.default.execution.isolation.thread.timeoutinms
prop增加它,但看起来没有效果。我错过什么了吗


我可以使用
spring retry
项目,但它需要向evey方法添加
@Retryable
注释,并且我希望对所有外部客户端进行默认重试。非常感谢您的帮助和建议。

您找到了解决此问题的方法吗?