Bug report
Spring Cloud version:Greenwich.SR2 Ribbon-core version:2.3.0
I want to use the retry mechanism of the ribbon, but it does not take effect after the retry attribute is configured.
After reading the source code, I found that the attribute specified in application.yml is not set to the corresponding attribute.
my application.yml:
spring-cloud-provider-application:
ribbon:
ConnectTimeout: 4000
ReadTimeout: 4000
OkToRetryOnAllOperations: true
MaxAutoRetries: 3
MaxAutoRetriesNextServer: 3
source code: org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer#getRequestSpecificRetryHandler
@Override
public RequestSpecificRetryHandler getRequestSpecificRetryHandler(
RibbonRequest request, IClientConfig requestConfig) {
// this condition is true
if (this.ribbon.isOkToRetryOnAllOperations()) {
return new RequestSpecificRetryHandler(true, true, this.getRetryHandler(),
requestConfig);
}
if (!request.toRequest().httpMethod().name().equals("GET")) {
return new RequestSpecificRetryHandler(true, false, this.getRetryHandler(),
requestConfig);
}
else {
return new RequestSpecificRetryHandler(true, true, this.getRetryHandler(),
requestConfig);
}
}
com.netflix.client.RequestSpecificRetryHandler#RequestSpecificRetryHandler(boolean, boolean, com.netflix.client.RetryHandler, com.netflix.client.config.IClientConfig)
public RequestSpecificRetryHandler(boolean okToRetryOnConnectErrors, boolean okToRetryOnAllErrors, RetryHandler baseRetryHandler, @Nullable IClientConfig requestConfig) {
Preconditions.checkNotNull(baseRetryHandler);
this.okToRetryOnConnectErrors = okToRetryOnConnectErrors;
this.okToRetryOnAllErrors = okToRetryOnAllErrors;
this.fallback = baseRetryHandler;
// this requestConfig is FeignOptionsClientConfig, it can not contains MaxAutoRetries attribute, so retry can not effect, i think requestConfig attribute should come from the clientConfig property of FeignLoadBalancer
if (requestConfig != null) {
if (requestConfig.containsProperty(CommonClientConfigKey.MaxAutoRetries)) {
retrySameServer = requestConfig.get(CommonClientConfigKey.MaxAutoRetries);
}
if (requestConfig.containsProperty(CommonClientConfigKey.MaxAutoRetriesNextServer)) {
retryNextServer = requestConfig.get(CommonClientConfigKey.MaxAutoRetriesNextServer);
}
}
}