According to the spring batch/retry documentation (http://docs.spring.io/spring-batch/reference/html/retry.html) in section 9.2 one can specify which exceptions you would like to retry or not retry on via setRetryableExceptions or setFatalExceptions when using the SimpleRetryPolicy. However, these methods are not defined in the current release (1.0.3) in GitHub https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/RetryPolicy.java .
So, is this a documentation error? If not, then where are the methods located?
From the source code, it seems that only the retryable exceptions can be set via the constructor that takes a Map of exceptions. There doesn't appear to be a way to define the fatal exceptions.
Spring Retry provides an ability to automatically re-invoke a failed operation. This is helpful where the errors may be transient (like a momentary network glitch).
To enable spring-retry we need to put one annotation in the Spring Boot Application class. So open SpringRetryApplication class and add @EnableRetry in class level.
Adding Retries to ItemProcessor If so, our batch job will fail. Here, we have a call to faultTolerant() for enabling the retry functionality. Additionally, we use retry and retryLimit to define the exceptions that qualify for a retry and the maximum retry count for an item, respectively.
Stateful retry is generally used by a message-driven source - e.g. RabbitMQ, JMS, where the message is rejected all the way back to the broker and redelivered for each retry.
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);
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