Class RequestHandlerRetryAdvice
- All Implemented Interfaces:
Advice,Interceptor,MethodInterceptor,Aware,BeanFactoryAware,BeanNameAware,InitializingBean,ApplicationContextAware,ComponentSourceAware,ExpressionCapable,NamedComponent
AbstractRequestHandlerAdvice implementation for retrying the target
MessageHandler execution.
By default, this advice performs 3 attempts (plus initial execution) with no delay in between.
If setStateKeyFunction(Function) is provided, the retry logic is turned into a stateful algorithm.
In this case, a BackOffExecution is cached by the mentioned retry state key if an exception is retryable.
Then this exception is thrown back to the caller, e.g.,
for transaction rollback or re-queueing the message onto message broker.
The next time when a message with the same key arrives again (redelivered),
the cached BackOffExecution is restored, and the target service is called again
immediately according to the RetryPolicy.
If the setNewMessagePredicate(Predicate) returns true,
a new stateful retry cycle is started even if a state for this message is already cached.
- Since:
- 2.2
- Author:
- Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException -
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable ObjectdoInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Subclasses implement this method to apply behavior to theMessageHandler.voidsetNewMessagePredicate(Predicate<Message<?>> newMessagePredicate) Set aPredicateto determine if a fresh stateful retry state should be started for this request message.voidsetRecoveryCallback(RecoveryCallback<Object> recoveryCallback) Set aRecoveryCallbackto handle aRetryException.voidsetRetryListener(org.springframework.core.retry.RetryListener retryListener) Set aRetryListenerto track retry cycle phases.voidsetRetryPolicy(org.springframework.core.retry.RetryPolicy retryPolicy) Set aRetryPolicyto use.voidsetStateCacheSize(int stateCacheSize) The size of the stateful retry state cache.voidsetStateKeyFunction(Function<Message<?>, Object> stateKeyFunction) Set aFunctionto determine a stateful retry execution key against a request message.Methods inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
getComponentType, invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessaryMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, onInit, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Constructor Details
-
RequestHandlerRetryAdvice
public RequestHandlerRetryAdvice()
-
-
Method Details
-
setRetryPolicy
public void setRetryPolicy(org.springframework.core.retry.RetryPolicy retryPolicy) Set aRetryPolicyto use. Defaults to 3 attempts with no delay in between.- Parameters:
retryPolicy- the policy.
-
setRetryListener
public void setRetryListener(org.springframework.core.retry.RetryListener retryListener) Set aRetryListenerto track retry cycle phases.- Parameters:
retryListener- the listener to use.
-
setRecoveryCallback
Set aRecoveryCallbackto handle aRetryException.- Parameters:
recoveryCallback- the callback to use.
-
setStateKeyFunction
Set aFunctionto determine a stateful retry execution key against a request message. If not provided, the retry behavior is stateless.- Parameters:
stateKeyFunction- the function to determine a stateful retry execution key against a request message.
-
setStateCacheSize
public void setStateCacheSize(int stateCacheSize) The size of the stateful retry state cache. Defaults to 100. This option is used only whensetStateKeyFunction(Function)is provided.- Parameters:
stateCacheSize- the size of the cache.
-
setNewMessagePredicate
Set aPredicateto determine if a fresh stateful retry state should be started for this request message.falseby default to not refresh existing stateful retry states. This option is used only whensetStateKeyFunction(Function)is provided.- Parameters:
newMessagePredicate- the predicate to use.
-
doInvoke
protected @Nullable Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Description copied from class:AbstractRequestHandlerAdviceSubclasses implement this method to apply behavior to theMessageHandler.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvokein classAbstractRequestHandlerAdvice- Parameters:
callback- Subclasses invoke the execute() method on this interface to invoke the handler method.target- The target handler.message- The message that will be sent to the handler.- Returns:
- the result after invoking the
MessageHandler.
-