Class RetryInterceptorBuilder<B extends RetryInterceptorBuilder<B,T>,T extends MethodInterceptor>
- java.lang.Object
-
- org.springframework.amqp.rabbit.config.RetryInterceptorBuilder<B,T>
-
- Type Parameters:
B
- The targetRetryInterceptorBuilder
implementation type.T
- The type ofMethodInterceptor
returned by the builder'sbuild()
method.
- Direct Known Subclasses:
RetryInterceptorBuilder.StatefulRetryInterceptorBuilder
,RetryInterceptorBuilder.StatelessRetryInterceptorBuilder
public abstract class RetryInterceptorBuilder<B extends RetryInterceptorBuilder<B,T>,T extends MethodInterceptor> extends 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();
- Since:
- 1.3
- Author:
- James Carr, Gary Russell, Artem Bilan
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RetryInterceptorBuilder.StatefulRetryInterceptorBuilder
Builder for a stateful interceptor.static class
RetryInterceptorBuilder.StatelessRetryInterceptorBuilder
Builder for a stateless interceptor.
-
Constructor Summary
Constructors Constructor Description RetryInterceptorBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected B
_this()
protected void
applyCommonSettings(AbstractRetryOperationsInterceptorFactoryBean factoryBean)
B
backOffOptions(long initialInterval, double multiplier, long maxInterval)
Apply the backoff options.B
backOffPolicy(org.springframework.retry.backoff.BackOffPolicy policy)
Apply the back off policy.abstract T
build()
B
maxAttempts(int maxAttempts)
Apply the max attempts - a SimpleRetryPolicy will be used.B
recoverer(MessageRecoverer recoverer)
Apply a Message recoverer - default is to log and discard after retry is exhausted.B
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.B
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.
-
-
-
Method Detail
-
stateful
public static RetryInterceptorBuilder.StatefulRetryInterceptorBuilder stateful()
Create a builder for a stateful retry interceptor.- Returns:
- The interceptor builder.
-
stateless
public static RetryInterceptorBuilder.StatelessRetryInterceptorBuilder stateless()
Create a builder for a stateless retry interceptor.- Returns:
- The interceptor builder.
-
_this
protected final B _this()
-
retryOperations
public B 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.- Parameters:
retryOperations
- The retry operations.- Returns:
- this.
-
maxAttempts
public B maxAttempts(int maxAttempts)
Apply the max attempts - a SimpleRetryPolicy will be used. Cannot be used if a custom retry operations or retry policy has been set.- Parameters:
maxAttempts
- the max attempts.- Returns:
- this.
-
backOffOptions
public B backOffOptions(long initialInterval, double multiplier, long maxInterval)
Apply the backoff options. Cannot be used if a custom retry operations, or back off policy has been set.- Parameters:
initialInterval
- The initial interval.multiplier
- The multiplier.maxInterval
- The max interval.- Returns:
- this.
-
retryPolicy
public B 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.- Parameters:
policy
- The policy.- Returns:
- this.
-
backOffPolicy
public B backOffPolicy(org.springframework.retry.backoff.BackOffPolicy policy)
Apply the back off policy. Cannot be used if a custom retry operations, or back off policy has been applied.- Parameters:
policy
- The policy.- Returns:
- this.
-
recoverer
public B recoverer(MessageRecoverer recoverer)
Apply a Message recoverer - default is to log and discard after retry is exhausted.- Parameters:
recoverer
- The recoverer.- Returns:
- this.
-
applyCommonSettings
protected void applyCommonSettings(AbstractRetryOperationsInterceptorFactoryBean factoryBean)
-
build
public abstract T build()
-
-