I use both Feign retryer:
@Bean
public Retryer retryer() {
/*
* It'll retry only a given number of times, will start with some time interval, and then increase it with each retry up to provided maximum.
* Let's define it with starting interval of 100 milliseconds, the maximum interval of 3 seconds, and the maximum number of attempts of 5:
*/
return new Retryer.Default(100L, TimeUnit.SECONDS.toMillis(3L), 5);
}
and custom timeouts:
@Bean
public Builder proxyFeignBuilder() {
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
if (StringUtils.isNotEmpty(proxyHost)) {
final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
okHttpClient = new OkHttpClient.Builder().proxy(proxy).build();
}
return Feign.builder().options(new Request.Options(feignConnectTimeout, TimeUnit.MILLISECONDS, feignReadTimeout, TimeUnit.MILLISECONDS, true))
.client(new feign.okhttp.OkHttpClient(okHttpClient));
}
What I don't understand is the sequence of waiting times in case the request is not successful. Is it as follows?
Yes, here is the formula
long nextMaxInterval() {
long interval = (long) (period * Math.pow(1.5, attempt - 1));
return interval > maxPeriod ? maxPeriod : interval;
}
The number of attempt will decide how long the interval is and it's not over maxPeriod