我想管理重试。我有 openfeign 客户端,两个微服务。怎么做呢?当我设置 yaml 配置时:
foo:
ribbon:
MaxAutoRetries:5
这不起作用。在我的 pom.xml 中是 Spring Cloud Greenwich RELEASE、spring-retry 和 open-feign 依赖项。我不使用任何服务发现。
我添加到我的 feign 方法注释中:@FeignClient(name="foo", url="...") 和 @RibbonClient(name="foo")。
启动应用程序后以及执行 http feign 请求时,我没有看到任何功能区日志。是否应该在两个微服务上配置功能区?
您可以为
Configuration
的 feign 创建一个 Retryer
并设置您想要的值:
import feign.Retryer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignClientConfig {
@Bean
public Retryer retryer() {
// Default(long period, long maxPeriod, int maxAttempts)
return new Retryer.Default(1, 100, 3);
}
}
我也遇到了同样的问题,原因如下:
public CachingSpringLoadBalancerFactory(SpringClientFactory factory,
LoadBalancedRetryFactory loadBalancedRetryPolicyFactory) {
this.factory = factory;
this.loadBalancedRetryFactory = loadBalancedRetryPolicyFactory;
}
public FeignLoadBalancer create(String clientName) {
FeignLoadBalancer client = this.cache.get(clientName);
if (client != null) {
return client;
}
IClientConfig config = this.factory.getClientConfig(clientName);
ILoadBalancer lb = this.factory.getLoadBalancer(clientName);
ServerIntrospector serverIntrospector = this.factory.getInstance(clientName,
ServerIntrospector.class);
// because loadBalancedRetryFactory is null. add spring-retry dependency.
client = this.loadBalancedRetryFactory != null
? new RetryableFeignLoadBalancer(lb, config, serverIntrospector,
this.loadBalancedRetryFactory)
: new FeignLoadBalancer(lb, config, serverIntrospector);
this.cache.put(clientName, client);
return client;
}