Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring retry setRetryableExceptions, setFatalExceptions not available

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.

like image 714
user3537621 Avatar asked Apr 15 '14 20:04

user3537621


People also ask

How spring Retry works?

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).

How do you implement spring Retry?

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.

How do I retry a spring batch job?

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.

What is stateful Retry?

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.


1 Answers

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);
like image 65
membersound Avatar answered Nov 14 '22 20:11

membersound