2

How can I ask Spring Batch to retry a failed step after some amount of time?

If the step fails more than x number of times, I would like to no longer retry the step and have the entire job fail.

I'm using Java Config and prefer to not to use XML to configure the retry.

James
  • 2,876
  • 18
  • 72
  • 116

2 Answers2

5

If you are using Spring Batch prior of version 2.2.0 then use the Retry functionality included in the Spring Batch library.

As noted in the beginning of the above quoted Spring Batch documentation page for Retry:

The retry functionality was pulled out of Spring Batch as of 2.2.0. It is now part of a new library, Spring Retry.

Otherwise use directly the Spring Retry directly (spinoff the Spring Batch project) that is adding some nice declarative way to annotate the functionality you need:

@Service
class MyService {
    //...
    @Retryable(maxAttempts=5, backoff=@Backoff(delay=100, maxDelay=500))
    public myFunctionalityService() {
        // ...
    }
    // ...
}
dimitrisli
  • 20,895
  • 12
  • 59
  • 63
1

It's all right here

http://docs.spring.io/spring-batch/reference/html/retry.html

There are some implemented retry policies, but I think in your case you need to implement interface RetryPolicy so it will fit your needs.

arseniyandru
  • 760
  • 1
  • 7
  • 16
  • 1
    Unfortunately, this is a good feature list, but it doesn't explain how to use it. Some examples would be nice. – pojo-guy Jun 21 '19 at 23:57