1
@Retryable(value = {SocketTimeoutException.class, AmazonServiceException.class},
             backoff = @Backoff(delayExpression = "${retry.delay:10000}"),
             maxAttemptsExpression = "${retry.max-attempts:4}")

For SocketTimeoutException I want to set delay as 10000 but for AmazonServiceException I want to set it as 100. Is there a way to achieve this?

Thanks

Paras Thakur
  • 119
  • 1
  • 9
  • 1
    I don't think the annotation supports that, check also this question https://stackoverflow.com/questions/46911668/different-retry-attempts-for-different-exceptions-in-spring-retryable/53742582. – Marc Sep 08 '20 at 10:25

1 Answers1

0

I am facing with a similar problem currently and I couldn't found elegant solution for this. Below is a work around I think might help you:

@Retryable(value = {SocketTimeoutException.class},
             backoff = @Backoff(delayExpression = "${retry.delay:10000}"),
             maxAttemptsExpression = "${retry.max-attempts:4}")
void function1(){
   //do actual work here
}


@Retryable(value = {AmazonServiceException.class},
             backoff = @Backoff(delayExpression = "${retry.delay:100}"),
             maxAttemptsExpression = "${retry.max-attempts:4}")
void function2(){
   function1(); // call function1
}

Call function2 to execute your logic. Main idea here is to call another function from with in the first function and these two functions are configured with different BackOff delays.

There are situations where this can create some problem in terms for max attempts value. Specifically, in worstcase senario there can be total of 8 attempts of retry(4 + 4).