Pip
Pip

Reputation: 17

How to retry 5 times with intervals of 1, 5, 10, 30, 60 seconds using Spring Retry in Java

For example, the method was called at 12:00:00 but failed.

I like it to retry at 12:00:01, 12:00:06, 12:00:16, 12:00:46, 12:01:46

How could I make it happen using Spring Retry in Java

I tried the following Custom BackOff Policy but it shows error:

    @Autowired
    private BackOffPolicy customBackOffPolicy;

    @Retryable(value = Exception.class, maxAttempts = 6, backoff = @Backoff(customBackOffPolicy))
    public ResponseResult<List<String>> get() {
        System.out.println("start: " + LocalTime.now());
        ArrayList<String> list = new ArrayList<>(List.of("A", "B", "C"));
        System.out.println("done");
        return ResponseResult.success(list);
    }

error message

Upvotes: 0

Views: 589

Answers (0)

Related Questions