I am using Feign Ribbon client to talk to a service. I have a client that fails immediately after configured maxAutoRetries in ribbon. Is there a property in feign or ribbon like "wait and retry" which can wait for configured time and retry.
Asked
Active
Viewed 1,985 times
1 Answers
0
You can define a Retryer
Bean for this purpose.
@Configuration
public class RetryConfiguration {
@Bean
public Retryer retryer() {
// default retryer will retry 5 times waiting waiting
// 100 ms per retry with a 1.5* back off multiplier
return Retryer.Default();
}
}
You can create your own Retryer
implementation if your needs are different from the default.
Once defined, this retry configuration will be used when a RetryableException
is thrown during any Feign
calls. You may need to also register an ErrorDecoder
to ensure that the response from your endpoint is wrapped appropriately:
public class MyErrorDecoder implements ErrorDecoder {
@Override
public Exception decode(String methodKey, Response response) {
// handle the error, wrap and return
return new RetryableException(exception);
}
}
@Bean
public ErrorDecoder errorDecoder() {
return new MyErrorDecoder();
}

Kevin Davis
- 1,193
- 8
- 14
-
The retrier bean should return new Retryer.Default(); – Shmarkus Jul 28 '20 at 10:10