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 SummaryConstructors
- 
Method SummaryModifier 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 theRetryTopicConfigurationwith 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 theDltStrategytoDltStrategy.NO_DLT.Configure theDltStrategytoDltStrategy.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 anExponentialBackOffwith 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 aBackOffthat 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 providedThrowables.Configure the behavior to retry on the providedThrowable.Configure the behavior to retry on the providedThrowables.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- 
RetryTopicConfigurationBuilderpublic RetryTopicConfigurationBuilder()
 
- 
- 
Method Details- 
dltHandlerMethodConfigure a DLT handler method.- Parameters:
- beanName- the bean name.
- methodName- the method name.
- Returns:
- the builder.
- Since:
- 2.8
 
- 
concurrencyConfigure the concurrency for the retry and DLT containers.- Parameters:
- concurrency- the concurrency.
- Returns:
- the builder.
- Since:
- 3.0
 
- 
dltHandlerMethodConfigure a DLT handler method.- Parameters:
- endpointHandlerMethod- the handler method.
- Returns:
- the builder.
 
- 
doNotRetryOnDltFailureConfigure theDltStrategytoDltStrategy.FAIL_ON_ERROR.- Returns:
- the builder.
 
- 
dltProcessingFailureStrategyConfigure theDltStrategy.- Parameters:
- dltStrategy- the strategy.
- Returns:
- the builder.
 
- 
doNotConfigureDltConfigure theDltStrategytoDltStrategy.NO_DLT.- Returns:
- the builder.
 
- 
autoStartDltHandlerSet 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
 
- 
includeTopicsConfigure the topic names for which to use the target configuration.- Parameters:
- topicNames- the names.
- Returns:
- the builder.
 
- 
excludeTopicsConfigure the topic names for which the target configuration will NOT be used.- Parameters:
- topicNames- the names.
- Returns:
- the builder.
 
- 
includeTopicConfigure a topic name for which to use the target configuration.- Parameters:
- topicName- the name.
- Returns:
- the builder.
 
- 
excludeTopicConfigure a topic name for which the target configuration will NOT be used.- Parameters:
- topicName- the name.
- Returns:
- the builder.
 
- 
retryTopicSuffixConfigure the suffix to add to the retry topics.- Parameters:
- suffix- the suffix.
- Returns:
- the builder.
 
- 
dltSuffixConfigure the suffix to add to the DLT topic.- Parameters:
- suffix- the suffix.
- Returns:
- the builder.
 
- 
suffixTopicsWithIndexValuesConfigure the retry topic names to be suffixed with ordinal index values.- Returns:
- the builder.
- See Also:
 
- 
setTopicSuffixingStrategypublic RetryTopicConfigurationBuilder setTopicSuffixingStrategy(TopicSuffixingStrategy topicSuffixingStrategy) Configure the retry topic nameTopicSuffixingStrategy.- Parameters:
- topicSuffixingStrategy- the strategy.
- Returns:
- the builder.
 
- 
sameIntervalTopicReuseStrategypublic 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
 
- 
useSingleTopicForSameIntervalsConfigure 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 amaxDelayis provided), and to use a single retry topic for fixed backoff.- Returns:
- the builder.
- Since:
- 3.0.4
- See Also:
 
- 
maxAttemptsConfigure the maximum delivery attempts (including the first).- Parameters:
- maxAttempts- the attempts.
- Returns:
- the builder.
 
- 
timeoutAfterConfigure 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.
 
- 
exponentialBackoffpublic 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.
 
- 
exponentialBackoffpublic RetryTopicConfigurationBuilder exponentialBackoff(long initialInterval, double multiplier, long maxInterval, long jitter) Configure anExponentialBackOffwith a jitter value.- Parameters:
- initialInterval- the initial delay interval.
- multiplier- the multiplier.
- maxInterval- the maximum delay interval.
- jitter- the jitter value.
- Returns:
- the builder.
 
- 
fixedBackOffConfigure 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 aBackOffthat applies random delay between the specified minimum interval and maximum interval.- Parameters:
- minInterval- the minimum interval.
- maxInterval- the maximum interval.
- Returns:
- the builder.
 
- 
noBackoffConfigure aBackOffthat does not apply any delay.- Returns:
- the builder.
 
- 
customBackoffConfigure a customBackOff.- Parameters:
- backOff- the backOff
- Returns:
- the builder.
 
- 
fixedBackOffConfigure aFixedBackOff.- Parameters:
- interval- the interval.
- Returns:
- the builder.
 
- 
doNotAutoCreateRetryTopicsConfigure the topic creation behavior to NOT auto-create topics.- Returns:
- the builder.
 
- 
autoCreateTopicsWithpublic 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.
 
- 
autoCreateTopicspublic 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.
 
- 
retryOnConfigure the behavior to retry on the providedThrowable.- Parameters:
- throwable- the throwable.
- Returns:
- the builder.
 
- 
notRetryOnConfigure the behavior to NOT retry on the providedThrowable.- Parameters:
- throwable- the throwable.
- Returns:
- the builder.
 
- 
retryOnConfigure the behavior to retry on the providedThrowables.- Parameters:
- throwables- the throwables.
- Returns:
- the builder.
 
- 
notRetryOnConfigure the behavior to NOT retry on the providedThrowables.- Parameters:
- throwables- the throwables.
- Returns:
- the builder.
 
- 
traversingCausesConfigure the classifier to traverse the cause chain.- Returns:
- the builder.
 
- 
traversingCausesConfigure the classifier to traverse, or not, the cause chain.- Parameters:
- traversing- true to traverse.
- Returns:
- the builder.
 
- 
dltRoutingRulespublic 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
 
- 
listenerFactorypublic RetryTopicConfigurationBuilder listenerFactory(ConcurrentKafkaListenerContainerFactory<?, ?> factory) Configure the container factory to use.- Parameters:
- factory- the factory.
- Returns:
- the builder.
 
- 
listenerFactoryConfigure the container factory to use via its bean name.- Parameters:
- factoryBeanName- the factory bean name.
- Returns:
- the builder.
 
- 
createCreate theRetryTopicConfigurationwith the provided template.- Parameters:
- sendToTopicKafkaTemplate- the template.
- Returns:
- the configuration.
 
- 
newInstanceCreate a new instance of the builder.- Returns:
- the new instance.
 
 
- 
exponentialBackoff(long, double, long)