I have tried to boil down the simplest retry scenario possible. The retry is being ignored upon execution.
Application.java:
@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {
//...
This is within a Service class:
public Boolean processItem() {
Long id = 999L;
try {
retrieveItemWithRetry(id);
return true;
} catch (NoResultException e) {
return false;
}
}
@Retryable(include=NoResultException.class, backoff = @Backoff(delay = 500, maxDelay = 3000), maxAttempts = 5)
private void retrieveItemWithRetry(Long id) {
retrieveItem(id);
}
private OrderRequest retrieveItem(Long id) {
throw new NoResultException();
}
This should be the accepted answer, when you say "I figured out that if return something from the method that you trying to retry, then @Retryable () is not working." is wrong, you can actually return a object in the retry method, the point is that the method needs to be called from a bean. I solved it.
In spring boot 2.0.2 Release, I have observed that the @Retryable is not working if you have retryable and called method in same class. On debugging found that the pointcut is not getting built properly. For now, the workaround for this problem is that we need to write the method in a different class and call it.
Internal calls to @Retryable methods (within the same class) are not retryable; see my answer here from yesterday, which explains why. Further, @Retryable methods must be public.
Per @Retryable ‘s default behavior, the retry may happen up to three times, with a delay of one second between retries. 4.2. @Retryable and @Recover Here, the retry is attempted when an SQLException is thrown. The @Recover annotation defines a separate recovery method when a @Retryable method fails with a specified exception.
Internal calls to @Retryable
methods (within the same class) are not retryable; see my answer here from yesterday, which explains why.
Further, @Retryable
methods must be public.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With