Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Retryable is not being triggered [duplicate]

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();
}    
like image 335
Joe Essey Avatar asked Jan 26 '17 22:01

Joe Essey


People also ask

Why is @retryable() not working?

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.

Why @retryable is not working in Spring Boot?

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.

Are internal calls to @retryable methods in a class retryable?

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.

What is the difference between @retryable and @recover?

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.


1 Answers

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.

like image 164
Gary Russell Avatar answered Sep 28 '22 05:09

Gary Russell