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);
}
There is nothing built in to support that.
However, since your retry is conditional on
RemoteServiceNotAvailableException
simply throw some other exception ifisRetryNeeded
isfalse
.