Class RetryTopicConfigurationBuilder
java.lang.Object
org.springframework.kafka.retrytopic.RetryTopicConfigurationBuilder
Builder class to create
RetryTopicConfiguration
instances.- Since:
- 2.7
- Author:
- Tomaz Fernandes, Gary Russell, Adrian Chlebosz, Wang Zhiyang, Stephane Nicoll
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionautoCreateTopics
(@Nullable Boolean shouldCreate, @Nullable Integer numPartitions, @Nullable Short replicationFactor) Configure the topic creation behavior to optionally create topics with the provided properties.autoCreateTopicsWith
(@Nullable Integer numPartitions, @Nullable Short replicationFactor) Configure the topic creation behavior to auto-create topics with the provided properties.autoStartDltHandler
(@Nullable 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
(BackOff backOff) Configure a customBackOff
.dltHandlerMethod
(String beanName, String methodName) Configure a DLT handler method.dltHandlerMethod
(EndpointHandlerMethod endpointHandlerMethod) Configure a DLT handler method.dltProcessingFailureStrategy
(DltStrategy dltStrategy) Configure theDltStrategy
.Configure to set DLT routing rules causing the message to be redirected to the custom DLT when the configured exception has been thrown during message processing.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 anExponentialBackOff
.exponentialBackoff
(long initialInterval, double multiplier, long maxInterval, long jitter) Configure anExponentialBackOff
with a jitter value.fixedBackOff
(int interval) Configure aFixedBackOff
.fixedBackOff
(long interval) Configure aFixedBackOff
.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
(@Nullable 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 aBackOff
that does not apply any delay.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
(@Nullable 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) Deprecated, for removal: This API element is subject to removal in a future version.Configure the use of a single retry topic for the attempts that have the same back off 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 back off 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 anExponentialBackOff
.- 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, long jitter) Configure anExponentialBackOff
with a jitter value.- Parameters:
initialInterval
- the initial delay interval.multiplier
- the multiplier.maxInterval
- the maximum delay interval.jitter
- the jitter value.- Returns:
- the builder.
-
fixedBackOff
Configure aFixedBackOff
.- Parameters:
interval
- the interval.- Returns:
- the builder.
-
uniformRandomBackoff
@Deprecated(since="4.0", forRemoval=true) public RetryTopicConfigurationBuilder uniformRandomBackoff(long minInterval, long maxInterval) Deprecated, for removal: This API element is subject to removal in a future version.since 4.0 in favor ofexponentialBackoff(long, double, long)
Configure aBackOff
that applies random delay between the specified minimum interval and maximum interval.- Parameters:
minInterval
- the minimum interval.maxInterval
- the maximum interval.- Returns:
- the builder.
-
noBackoff
Configure aBackOff
that does not apply any delay.- Returns:
- the builder.
-
customBackoff
Configure a customBackOff
.- Parameters:
backOff
- the backOff- Returns:
- the builder.
-
fixedBackOff
Configure aFixedBackOff
.- 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(@Nullable Integer numPartitions, @Nullable 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 earlier than version 2.4, an explicit value is required).- Returns:
- the builder.
-
autoCreateTopics
public RetryTopicConfigurationBuilder autoCreateTopics(@Nullable Boolean shouldCreate, @Nullable Integer numPartitions, @Nullable 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 earlier than version 2.4, an explicit value is required).- 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.
-
dltRoutingRules
public RetryTopicConfigurationBuilder dltRoutingRules(Map<String, Set<Class<? extends Throwable>>> dltRoutingRules) Configure to set DLT routing rules causing the message to be redirected to the custom DLT when the configured exception has been thrown during message processing. The cause of the originally thrown exception will be traversed in order to find the match with the configured exceptions.- Parameters:
dltRoutingRules
- specification of custom DLT name extensions and exceptions which should be matched for them- Returns:
- the builder
- Since:
- 3.2.0
-
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.
-
exponentialBackoff(long, double, long)