spring retry setRetryableExceptions, setFatalExceptions not available
Maybe this can help. You have to create a map holding all retryable exceptions by classtype, and add it to the policy. Probably similar with fatal exceptions.
Map<Class<? extends Throwable>, Boolean> r = new HashMap<>();r.put(RetryException.class, true);SimpleRetryPolicy p = new SimpleRetryPolicy(MAX_RETRIES, r);RetryTemplate t = new RetryTemplate();t.setRetryPolicy(p);
I had to implement Retry mechanism in my project as well and I created my own implementation.
This works like a charm (only i didn't find a way yet to ensure that only one aspect instance in instantiated at a time.)
You can just annotate your methods with the @Retry annotation, provide some config you want and its done.
These methods are no longer available. There is an issue posted by Gary to correct the documentation. You can pass a Map mentioning the set of fatal exceptions for which you don't want to retry.
@Bean public RetryTemplate retryTemplate() { RetryTemplate template = retryTemplate(); Map<Class<? extends Throwable>, Boolean> retryableExceptions = new HashMap<>(); retryableExceptions.put(Exception.class, true); retryableExceptions.put(RuntimeException.class, false); template.setRetryPolicy(new SimpleRetryPolicy(2,retryableExceptions)); return template; }
In the above example the template will retry for the family of Exception.class
except the RuntimeException.class
and its subclasses. Additionally, you can refer to the answer Gary has posted here for better understanding.