0

I have a class which has @Retryable annotation added to method with value as custom exception and maxAttempts =2 .

  @Override
  @Retryable(value = CustomException.class, maxAttempts = 2)
  public void process(String input) {
    //code logic
}

Currently this code is retried everytime there is a CustomException thrown in application but my code throws this CustomException in different ways like :

  1. throw new CustomException(CustomErrorCode.RETRY)
  2. throw new CustomException(CustomErrorCode.DONOTRETRY)

I want to retry CustomException which has errorcode Retry. Can anybody help?

1 Answers1

0

You cannot add conditions based on the exception properties; however, in the retryable method, you can do this:

RetrySynchronizationManager.getContext().setExhaustedOnly();

This prevents any retries.

/**
 * Signal to the framework that no more attempts should be made to try or retry the
 * current {@link RetryCallback}.
 */
void setExhaustedOnly();
Gary Russell
  • 166,535
  • 14
  • 146
  • 179