0

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.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Pradeep
  • 850
  • 2
  • 14
  • 27

1 Answers1

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