Using Spring Retry, I have a retry going on in 1 thread.
In some circumstances, I would like to be able to cancel the retry before it has reached the configured number of retries.
What is the best way to achieve this with this library?
I have tried wrapping the lambda passed into execute
so I can check whether or not the retry should be cancelled like this:
public <V, E extends Throwable> V execute(ThrowingSupplier<V, E> action) throws E {
return retryTemplate.execute(context -> {
if (shouldCancel()) {
//Do something to cancel the retry here
} else {
return action.get()
}
});
}
However, I feel like I am working against, rather than with, the framework by wrapping the retry template in this way.