Class RetryTopicConfigurationBuilder
java.lang.Object
org.springframework.kafka.retrytopic.RetryTopicConfigurationBuilder
Builder class to create
RetryTopicConfiguration
instances.- Since:
- 2.7
- Author:
- Tomaz Fernandes, Gary Russell
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionautoCreateTopics
(boolean shouldCreate, int numPartitions, short replicationFactor) Configure the topic creation behavior to optionally create topics with the provided properties.autoCreateTopicsWith
(int numPartitions, short replicationFactor) Configure the topic creation behavior to auto create topics with the provided properties.autoStartDltHandler
(Boolean autoStart) Set to false to not start the DLT handler (configured or default); overrides the container factory's autoStartup property.concurrency
(Integer concurrency) Configure the concurrency for the retry and DLT containers.create
(KafkaOperations<?, ?> sendToTopicKafkaTemplate) Create theRetryTopicConfiguration
with the provided template.customBackoff
(org.springframework.retry.backoff.SleepingBackOffPolicy<?> backOffPolicy) Configure a customSleepingBackOffPolicy
.dltHandlerMethod
(String beanName, String methodName) Configure a DLT handler method.dltHandlerMethod
(EndpointHandlerMethod endpointHandlerMethod) Configure a DLT handler method.dltProcessingFailureStrategy
(DltStrategy dltStrategy) Configure theDltStrategy
.Configure the suffix to add to the DLT topic.Configure the topic creation behavior to NOT auto create topics.Configure theDltStrategy
toDltStrategy.NO_DLT
.Configure theDltStrategy
toDltStrategy.FAIL_ON_ERROR
.excludeTopic
(String topicName) Configure a topic name for which the target configuration will NOT be used.excludeTopics
(List<String> topicNames) Configure the topic names for which the target configuration will NOT be used.exponentialBackoff
(long initialInterval, double multiplier, long maxInterval) Configure anExponentialBackOffPolicy
.exponentialBackoff
(long initialInterval, double multiplier, long maxInterval, boolean withRandom) Configure anExponentialBackOffPolicy
orExponentialRandomBackOffPolicy
depending on the random parameter.fixedBackOff
(int interval) Configure aFixedBackOffPolicy
.fixedBackOff
(long interval) Configure aFixedBackOffPolicy
.includeTopic
(String topicName) Configure a topic name for which to use the target configuration.includeTopics
(List<String> topicNames) Configure the topic names for which to use the target configuration.listenerFactory
(String factoryBeanName) Configure the container factory to use via its bean name.listenerFactory
(ConcurrentKafkaListenerContainerFactory<?, ?> factory) Configure the container factory to use.maxAttempts
(int maxAttempts) Configure the maximum delivery attempts (including the first).Create a new instance of the builder.Configure aNoBackOffPolicy
.notRetryOn
(Class<? extends Throwable> throwable) Configure the behavior to NOT retry on the providedThrowable
.notRetryOn
(List<Class<? extends Throwable>> throwables) Configure the behavior to NOT retry on the providedThrowable
s.Configure the behavior to retry on the providedThrowable
.Configure the behavior to retry on the providedThrowable
s.retryTopicSuffix
(String suffix) Configure the suffix to add to the retry topics.sameIntervalTopicReuseStrategy
(SameIntervalTopicReuseStrategy sameIntervalTopicReuseStrategy) Configure theSameIntervalTopicReuseStrategy
.setTopicSuffixingStrategy
(TopicSuffixingStrategy topicSuffixingStrategy) Configure the retry topic nameTopicSuffixingStrategy
.Configure the retry topic names to be suffixed with ordinal index values.timeoutAfter
(long timeout) Configure a global timeout, in milliseconds, after which a record will go straight to the DLT the next time a listener throws an exception.Configure the classifier to traverse the cause chain.traversingCauses
(boolean traversing) Configure the classifier to traverse, or not, the cause chain.uniformRandomBackoff
(long minInterval, long maxInterval) Configure aUniformRandomBackOffPolicy
.Configure the use of a single retry topic for the attempts that have the same backoff interval (as long as these attempts are in the end of the chain).
-
Constructor Details
-
RetryTopicConfigurationBuilder
public RetryTopicConfigurationBuilder()
-
-
Method Details
-
dltHandlerMethod
Configure a DLT handler method.- Parameters:
beanName
- the bean name.methodName
- the method name.- Returns:
- the builder.
- Since:
- 2.8
-
concurrency
Configure the concurrency for the retry and DLT containers.- Parameters:
concurrency
- the concurrency.- Returns:
- the builder.
- Since:
- 3.0
-
dltHandlerMethod
Configure a DLT handler method.- Parameters:
endpointHandlerMethod
- the handler method.- Returns:
- the builder.
-
doNotRetryOnDltFailure
Configure theDltStrategy
toDltStrategy.FAIL_ON_ERROR
.- Returns:
- the builder.
-
dltProcessingFailureStrategy
Configure theDltStrategy
.- Parameters:
dltStrategy
- the strategy.- Returns:
- the builder.
-
doNotConfigureDlt
Configure theDltStrategy
toDltStrategy.NO_DLT
.- Returns:
- the builder.
-
autoStartDltHandler
Set to false to not start the DLT handler (configured or default); overrides the container factory's autoStartup property.- Parameters:
autoStart
- false to not auto start.- Returns:
- this builder.
- Since:
- 2.8
-
includeTopics
Configure the topic names for which to use the target configuration.- Parameters:
topicNames
- the names.- Returns:
- the builder.
-
excludeTopics
Configure the topic names for which the target configuration will NOT be used.- Parameters:
topicNames
- the names.- Returns:
- the builder.
-
includeTopic
Configure a topic name for which to use the target configuration.- Parameters:
topicName
- the name.- Returns:
- the builder.
-
excludeTopic
Configure a topic name for which the target configuration will NOT be used.- Parameters:
topicName
- the name.- Returns:
- the builder.
-
retryTopicSuffix
Configure the suffix to add to the retry topics.- Parameters:
suffix
- the suffix.- Returns:
- the builder.
-
dltSuffix
Configure the suffix to add to the DLT topic.- Parameters:
suffix
- the suffix.- Returns:
- the builder.
-
suffixTopicsWithIndexValues
Configure the retry topic names to be suffixed with ordinal index values.- Returns:
- the builder.
- See Also:
-
setTopicSuffixingStrategy
public RetryTopicConfigurationBuilder setTopicSuffixingStrategy(TopicSuffixingStrategy topicSuffixingStrategy) Configure the retry topic nameTopicSuffixingStrategy
.- Parameters:
topicSuffixingStrategy
- the strategy.- Returns:
- the builder.
-
sameIntervalTopicReuseStrategy
public RetryTopicConfigurationBuilder sameIntervalTopicReuseStrategy(SameIntervalTopicReuseStrategy sameIntervalTopicReuseStrategy) Configure theSameIntervalTopicReuseStrategy
.Note: for fixed backoffs, when this is configured as
SameIntervalTopicReuseStrategy.SINGLE_TOPIC
, it has precedence over the configuration done throughuseSingleTopicForSameIntervals()
.- Parameters:
sameIntervalTopicReuseStrategy
- the strategy.- Returns:
- the builder.
- Since:
- 3.0.4
-
useSingleTopicForSameIntervals
Configure the use of a single retry topic for the attempts that have the same backoff interval (as long as these attempts are in the end of the chain). Used for the last retries of exponential backoff (when amaxDelay
is provided), and to use a single retry topic for fixed backoff.- Returns:
- the builder.
- Since:
- 3.0.4
- See Also:
-
maxAttempts
Configure the maximum delivery attempts (including the first).- Parameters:
maxAttempts
- the attempts.- Returns:
- the builder.
-
timeoutAfter
Configure a global timeout, in milliseconds, after which a record will go straight to the DLT the next time a listener throws an exception. Default no timeout.- Parameters:
timeout
- the timeout.- Returns:
- the builder.
-
exponentialBackoff
public RetryTopicConfigurationBuilder exponentialBackoff(long initialInterval, double multiplier, long maxInterval) Configure anExponentialBackOffPolicy
.- Parameters:
initialInterval
- the initial delay interval.multiplier
- the multiplier.maxInterval
- the maximum delay interval.- Returns:
- the builder.
-
exponentialBackoff
public RetryTopicConfigurationBuilder exponentialBackoff(long initialInterval, double multiplier, long maxInterval, boolean withRandom) Configure anExponentialBackOffPolicy
orExponentialRandomBackOffPolicy
depending on the random parameter.- Parameters:
initialInterval
- the initial delay interval.multiplier
- the multiplier.maxInterval
- the maximum delay interval.withRandom
- true for anExponentialRandomBackOffPolicy
.- Returns:
- the builder.
-
fixedBackOff
Configure aFixedBackOffPolicy
.- Parameters:
interval
- the interval.- Returns:
- the builder.
-
uniformRandomBackoff
Configure aUniformRandomBackOffPolicy
.- Parameters:
minInterval
- the minimum interval.maxInterval
- the maximum interval.- Returns:
- the builder.
-
noBackoff
Configure aNoBackOffPolicy
.- Returns:
- the builder.
-
customBackoff
public RetryTopicConfigurationBuilder customBackoff(org.springframework.retry.backoff.SleepingBackOffPolicy<?> backOffPolicy) Configure a customSleepingBackOffPolicy
.- Parameters:
backOffPolicy
- the policy.- Returns:
- the builder.
-
fixedBackOff
Configure aFixedBackOffPolicy
.- Parameters:
interval
- the interval.- Returns:
- the builder.
-
doNotAutoCreateRetryTopics
Configure the topic creation behavior to NOT auto create topics.- Returns:
- the builder.
-
autoCreateTopicsWith
public RetryTopicConfigurationBuilder autoCreateTopicsWith(int numPartitions, short replicationFactor) Configure the topic creation behavior to auto create topics with the provided properties.- Parameters:
numPartitions
- the number of partitions.replicationFactor
- the replication factor (-1 to use the broker default if the broker is version 2.4 or later).- Returns:
- the builder.
-
autoCreateTopics
public RetryTopicConfigurationBuilder autoCreateTopics(boolean shouldCreate, int numPartitions, short replicationFactor) Configure the topic creation behavior to optionally create topics with the provided properties.- Parameters:
shouldCreate
- true to auto create.numPartitions
- the number of partitions.replicationFactor
- the replication factor (-1 to use the broker default if the broker is version 2.4 or later).- Returns:
- the builder.
-
retryOn
Configure the behavior to retry on the providedThrowable
.- Parameters:
throwable
- the throwable.- Returns:
- the builder.
-
notRetryOn
Configure the behavior to NOT retry on the providedThrowable
.- Parameters:
throwable
- the throwable.- Returns:
- the builder.
-
retryOn
Configure the behavior to retry on the providedThrowable
s.- Parameters:
throwables
- the throwables.- Returns:
- the builder.
-
notRetryOn
Configure the behavior to NOT retry on the providedThrowable
s.- Parameters:
throwables
- the throwables.- Returns:
- the builder.
-
traversingCauses
Configure the classifier to traverse the cause chain.- Returns:
- the builder.
-
traversingCauses
Configure the classifier to traverse, or not, the cause chain.- Parameters:
traversing
- true to traverse.- Returns:
- the builder.
-
listenerFactory
public RetryTopicConfigurationBuilder listenerFactory(ConcurrentKafkaListenerContainerFactory<?, ?> factory) Configure the container factory to use.- Parameters:
factory
- the factory.- Returns:
- the builder.
-
listenerFactory
Configure the container factory to use via its bean name.- Parameters:
factoryBeanName
- the factory bean name.- Returns:
- the builder.
-
create
Create theRetryTopicConfiguration
with the provided template.- Parameters:
sendToTopicKafkaTemplate
- the template.- Returns:
- the configuration.
-
newInstance
Create a new instance of the builder.- Returns:
- the new instance.
-