spring retry with custom boolean value from the request

752 Views Asked by At

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

}
1

There are 1 best solutions below

1
On BEST ANSWER

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.