Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring @Retryable for specific condition

Is it possible to retry based on certain conditions? If I annotate with Retryable, it will retry based on some Exceptions but I want to retry if that exception is caught and the corresponding conditions is met. Example:

@Retryable(value={MyException.class},maxAttempts=2)
public myMethod(Request request){

    try{
        doSomething();
    } Catch(Exception ex){
        throw new MyException();
    }

}

Here in the above request, I have a flag, isRetryRequired if that is true and MyException is caught then I want to retry

like image 566
user123475 Avatar asked Nov 08 '22 15:11

user123475


1 Answers

Not directly in the annotation; you would need a custom retry policy via the interceptor property.

like image 77
Gary Russell Avatar answered Nov 14 '22 22:11

Gary Russell