I have this piece of code
@Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class,
exclude = URISyntaxException.class, backoff = @Backoff(delay = 1000, multiplier = 2) )
public void testThatService(String serviceAccountId)
throws ServiceUnavailableException, URISyntaxException {
//some implementation here }
Is there a way I can make the maxAttempts , delay and multiplier configurable using @Value? Or is there any other approach to make such fields inside annotations configurable?
Spring Retry provides the ability to automatically re-invoke a failed operation. This is helpful when errors may be transient in nature. For example, a momentary network glitch, network outage, server down, or deadlock.
public class RetryTemplate extends Object implements RetryOperations. Template class that simplifies the execution of operations with retry semantics. Retryable operations are encapsulated in implementations of the RetryCallback interface and are executed using one of the supplied execute methods.
public interface RetryContext extends org.springframework.core.AttributeAccessor. Low-level access to ongoing retry operation. Normally not needed by clients, but can be used to alter the course of the retry, e.g. force an early termination.
Does the default spring-retry implementation block threads while retrying? The implementation in github indicates that it does.
with the release of Spring-retry version 1.2, it's possible. @Retryable can be configured using SPEL.
@Retryable(
value = { SomeException.class,AnotherException.class },
maxAttemptsExpression = "#{@myBean.getMyProperties('retryCount')}",
backoff = @Backoff(delayExpression = "#{@myBean.getMyProperties('retryInitalInterval')}"))
public void doJob(){
//your code here
}
For more details refer: https://github.com/spring-projects/spring-retry/blob/master/README.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With