T
- The type of MethodInterceptor
returned by the builder's build()
method.public abstract class RetryInterceptorBuilder<T extends org.aopalliance.intercept.MethodInterceptor>
extends java.lang.Object
Simplified facade to make it easier and simpler to build a
StatefulRetryOperationsInterceptor
or
(stateless) RetryOperationsInterceptor
by providing a fluent interface to defining the behavior on error.
Typical example:
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful() .maxAttempts(5) .backOffOptions(1, 2, 10) // initialInterval, multiplier, maxInterval .build();
When building a stateful interceptor, a message identifier is required.
The default behavior determines message identity based on messageId
.
This isn't a required field and may not be set by the sender.
If it is not, you can change the logic to determine message
identity using a custom generator:
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful() .messageKeyGenerator(new MyMessageKeyGenerator()) .build();
Modifier and Type | Class and Description |
---|---|
static class |
RetryInterceptorBuilder.StatefulRetryInterceptorBuilder
Builder for a stateful interceptor.
|
static class |
RetryInterceptorBuilder.StatelessRetryInterceptorBuilder
Builder for a stateless interceptor.
|
Constructor and Description |
---|
RetryInterceptorBuilder() |
Modifier and Type | Method and Description |
---|---|
protected void |
applyCommonSettings(AbstractRetryOperationsInterceptorFactoryBean factoryBean) |
RetryInterceptorBuilder<T> |
backOffOptions(long initialInterval,
double multiplier,
long maxInterval)
Apply the backoff options.
|
RetryInterceptorBuilder<T> |
backOffPolicy(org.springframework.retry.backoff.BackOffPolicy policy)
Apply the back off policy.
|
abstract T |
build() |
RetryInterceptorBuilder<T> |
maxAttempts(int maxAttempts)
Apply the max attempts - a SimpleRetryPolicy will be used.
|
RetryInterceptorBuilder<T> |
recoverer(MessageRecoverer recoverer)
Apply a Message recoverer - default is to log and discard after retry is exhausted.
|
RetryInterceptorBuilder<T> |
retryOperations(org.springframework.retry.RetryOperations retryOperations)
Apply the retry operations - once this is set, other properties can no longer be set; can't
be set if other properties have been applied.
|
RetryInterceptorBuilder<T> |
retryPolicy(org.springframework.retry.RetryPolicy policy)
Apply the retry policy - cannot be used if a custom retry template has been provided, or the max attempts or
back off options or policy have been applied.
|
static RetryInterceptorBuilder.StatefulRetryInterceptorBuilder |
stateful()
Create a builder for a stateful retry interceptor.
|
static RetryInterceptorBuilder.StatelessRetryInterceptorBuilder |
stateless()
Create a builder for a stateless retry interceptor.
|
public static RetryInterceptorBuilder.StatefulRetryInterceptorBuilder stateful()
public static RetryInterceptorBuilder.StatelessRetryInterceptorBuilder stateless()
public RetryInterceptorBuilder<T> retryOperations(org.springframework.retry.RetryOperations retryOperations)
retryOperations
- The retry operations.public RetryInterceptorBuilder<T> maxAttempts(int maxAttempts)
maxAttempts
- the max attempts.public RetryInterceptorBuilder<T> backOffOptions(long initialInterval, double multiplier, long maxInterval)
initialInterval
- The initial interval.multiplier
- The multiplier.maxInterval
- The max interval.public RetryInterceptorBuilder<T> retryPolicy(org.springframework.retry.RetryPolicy policy)
policy
- The policy.public RetryInterceptorBuilder<T> backOffPolicy(org.springframework.retry.backoff.BackOffPolicy policy)
policy
- The policy.public RetryInterceptorBuilder<T> recoverer(MessageRecoverer recoverer)
recoverer
- The recoverer.protected void applyCommonSettings(AbstractRetryOperationsInterceptorFactoryBean factoryBean)
public abstract T build()