0

I am newbie in spring annotations and spring retry. Below is the sample code, my query is based on the method argument isRetryNeeded, I need to decide if a retry(here 3 times) is needed or not. Thank you

package com.example.retry;

import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;

public interface BackendAdapter {

    @Retryable(value = { RemoteServiceNotAvailableException.class }, maxAttempts = 3, backoff = @Backoff(delay = 1000))
    public String getBackendResponse(boolean isRetryNeeded, boolean simulateretryfallback);

    @Recover
    public String getBackendResponseFallback(RuntimeException e);

}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
Teja
  • 69
  • 7

1 Answers1

0

There is nothing built in to support that.

However, since your retry is conditional on RemoteServiceNotAvailableException simply throw some other exception if isRetryNeeded is false.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179