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 targetRetryInterceptorBuilderimplementation type.T- The type ofMethodInterceptorreturned 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
StatelessRetryOperationsInterceptor by providing a fluent interface to
defining the behavior on error.
Typical example:
StatefulRetryOperationsInterceptor interceptor =
RetryInterceptorBuilder.stateful()
.maxRetries(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, Stephane Nicoll
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for a stateful interceptor.static final classBuilder for a stateless interceptor. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final B_this()protected voidbackOffOptions(long initialInterval, double multiplier, long maxInterval) Apply the backoff options.abstract Tbuild()configureRetryPolicy(Consumer<RetryPolicy.Builder> retryPolicy) Configure theRetryPolicy.maxRetries(int maxRetries) Apply the max retries - a SimpleRetryPolicy will be used.recoverer(MessageRecoverer recoverer) Apply a Message recoverer - default is to log and discard after retry is exhausted.retryPolicy(RetryPolicy policy) Apply the retry policy - cannot be used if a custom retry template has been provided or if the retry policy has been customized already.stateful()Create a builder for a stateful retry interceptor.Create a builder for a stateless retry interceptor.
-
Constructor Details
-
RetryInterceptorBuilder
public RetryInterceptorBuilder()
-
-
Method Details
-
stateful
Create a builder for a stateful retry interceptor.- Returns:
- The interceptor builder.
-
stateless
Create a builder for a stateless retry interceptor.- Returns:
- The interceptor builder.
-
_this
-
retryPolicy
Apply the retry policy - cannot be used if a custom retry template has been provided or if the retry policy has been customized already.- Parameters:
policy- The policy.- Returns:
- this.
-
configureRetryPolicy
Configure theRetryPolicy. Cannot be used if a custom retry operations or retry policy has been set.- Parameters:
retryPolicy- a consumer to customize the builder- Returns:
- this.
-
maxRetries
Apply the max retries - a SimpleRetryPolicy will be used. Cannot be used if a custom retry operations or retry policy has been set.- Parameters:
maxRetries- the maximum number of retry attempts..- Returns:
- this.
-
backOffOptions
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.
-
recoverer
Apply a Message recoverer - default is to log and discard after retry is exhausted.- Parameters:
recoverer- The recoverer.- Returns:
- this.
-
applyCommonSettings
-
build
-