Class RetryTopicConfigurationBuilder

java.lang.Object
org.springframework.kafka.retrytopic.RetryTopicConfigurationBuilder

public class RetryTopicConfigurationBuilder extends Object
Builder class to create RetryTopicConfiguration instances.
Since:
2.7
Author:
Tomaz Fernandes, Gary Russell, Adrian Chlebosz, Wang Zhiyang
  • Constructor Details

    • RetryTopicConfigurationBuilder

      public RetryTopicConfigurationBuilder()
  • Method Details

    • dltHandlerMethod

      public RetryTopicConfigurationBuilder dltHandlerMethod(String beanName, String methodName)
      Configure a DLT handler method.
      Parameters:
      beanName - the bean name.
      methodName - the method name.
      Returns:
      the builder.
      Since:
      2.8
    • concurrency

      public RetryTopicConfigurationBuilder concurrency(Integer concurrency)
      Configure the concurrency for the retry and DLT containers.
      Parameters:
      concurrency - the concurrency.
      Returns:
      the builder.
      Since:
      3.0
    • dltHandlerMethod

      public RetryTopicConfigurationBuilder dltHandlerMethod(EndpointHandlerMethod endpointHandlerMethod)
      Configure a DLT handler method.
      Parameters:
      endpointHandlerMethod - the handler method.
      Returns:
      the builder.
    • doNotRetryOnDltFailure

      public RetryTopicConfigurationBuilder doNotRetryOnDltFailure()
      Returns:
      the builder.
    • dltProcessingFailureStrategy

      public RetryTopicConfigurationBuilder dltProcessingFailureStrategy(DltStrategy dltStrategy)
      Configure the DltStrategy.
      Parameters:
      dltStrategy - the strategy.
      Returns:
      the builder.
    • doNotConfigureDlt

      public RetryTopicConfigurationBuilder doNotConfigureDlt()
      Returns:
      the builder.
    • autoStartDltHandler

      public RetryTopicConfigurationBuilder autoStartDltHandler(@Nullable Boolean autoStart)
      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

      public RetryTopicConfigurationBuilder includeTopics(List<String> topicNames)
      Configure the topic names for which to use the target configuration.
      Parameters:
      topicNames - the names.
      Returns:
      the builder.
    • excludeTopics

      public RetryTopicConfigurationBuilder excludeTopics(List<String> topicNames)
      Configure the topic names for which the target configuration will NOT be used.
      Parameters:
      topicNames - the names.
      Returns:
      the builder.
    • includeTopic

      public RetryTopicConfigurationBuilder includeTopic(String topicName)
      Configure a topic name for which to use the target configuration.
      Parameters:
      topicName - the name.
      Returns:
      the builder.
    • excludeTopic

      public RetryTopicConfigurationBuilder excludeTopic(String topicName)
      Configure a topic name for which the target configuration will NOT be used.
      Parameters:
      topicName - the name.
      Returns:
      the builder.
    • retryTopicSuffix

      public RetryTopicConfigurationBuilder retryTopicSuffix(@Nullable String suffix)
      Configure the suffix to add to the retry topics.
      Parameters:
      suffix - the suffix.
      Returns:
      the builder.
    • dltSuffix

      public RetryTopicConfigurationBuilder dltSuffix(@Nullable String suffix)
      Configure the suffix to add to the DLT topic.
      Parameters:
      suffix - the suffix.
      Returns:
      the builder.
    • suffixTopicsWithIndexValues

      public RetryTopicConfigurationBuilder 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 name TopicSuffixingStrategy.
      Parameters:
      topicSuffixingStrategy - the strategy.
      Returns:
      the builder.
    • sameIntervalTopicReuseStrategy

      public RetryTopicConfigurationBuilder sameIntervalTopicReuseStrategy(SameIntervalTopicReuseStrategy sameIntervalTopicReuseStrategy)
      Configure the SameIntervalTopicReuseStrategy.

      Note: for fixed backoffs, when this is configured as SameIntervalTopicReuseStrategy.SINGLE_TOPIC, it has precedence over the configuration done through useSingleTopicForSameIntervals().

      Parameters:
      sameIntervalTopicReuseStrategy - the strategy.
      Returns:
      the builder.
      Since:
      3.0.4
    • useSingleTopicForSameIntervals

      public RetryTopicConfigurationBuilder 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 a maxDelay is provided), and to use a single retry topic for fixed backoff.
      Returns:
      the builder.
      Since:
      3.0.4
      See Also:
    • maxAttempts

      public RetryTopicConfigurationBuilder maxAttempts(int maxAttempts)
      Configure the maximum delivery attempts (including the first).
      Parameters:
      maxAttempts - the attempts.
      Returns:
      the builder.
    • timeoutAfter

      public RetryTopicConfigurationBuilder 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. Default no timeout.
      Parameters:
      timeout - the timeout.
      Returns:
      the builder.
    • exponentialBackoff

      public RetryTopicConfigurationBuilder exponentialBackoff(long initialInterval, double multiplier, long maxInterval)
      Configure an ExponentialBackOffPolicy.
      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 an ExponentialBackOffPolicy or ExponentialRandomBackOffPolicy depending on the random parameter.
      Parameters:
      initialInterval - the initial delay interval.
      multiplier - the multiplier.
      maxInterval - the maximum delay interval.
      withRandom - true for an ExponentialRandomBackOffPolicy.
      Returns:
      the builder.
    • fixedBackOff

      public RetryTopicConfigurationBuilder fixedBackOff(long interval)
      Configure a FixedBackOffPolicy.
      Parameters:
      interval - the interval.
      Returns:
      the builder.
    • uniformRandomBackoff

      public RetryTopicConfigurationBuilder uniformRandomBackoff(long minInterval, long maxInterval)
      Configure a UniformRandomBackOffPolicy.
      Parameters:
      minInterval - the minimum interval.
      maxInterval - the maximum interval.
      Returns:
      the builder.
    • noBackoff

      public RetryTopicConfigurationBuilder noBackoff()
      Configure a NoBackOffPolicy.
      Returns:
      the builder.
    • customBackoff

      public RetryTopicConfigurationBuilder customBackoff(org.springframework.retry.backoff.SleepingBackOffPolicy<?> backOffPolicy)
      Configure a custom SleepingBackOffPolicy.
      Parameters:
      backOffPolicy - the policy.
      Returns:
      the builder.
    • fixedBackOff

      public RetryTopicConfigurationBuilder fixedBackOff(int interval)
      Configure a FixedBackOffPolicy.
      Parameters:
      interval - the interval.
      Returns:
      the builder.
    • doNotAutoCreateRetryTopics

      public RetryTopicConfigurationBuilder 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 version 2.4 or later).
      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 version 2.4 or later).
      Returns:
      the builder.
    • retryOn

      public RetryTopicConfigurationBuilder retryOn(Class<? extends Throwable> throwable)
      Configure the behavior to retry on the provided Throwable.
      Parameters:
      throwable - the throwable.
      Returns:
      the builder.
    • notRetryOn

      public RetryTopicConfigurationBuilder notRetryOn(Class<? extends Throwable> throwable)
      Configure the behavior to NOT retry on the provided Throwable.
      Parameters:
      throwable - the throwable.
      Returns:
      the builder.
    • retryOn

      public RetryTopicConfigurationBuilder retryOn(List<Class<? extends Throwable>> throwables)
      Configure the behavior to retry on the provided Throwables.
      Parameters:
      throwables - the throwables.
      Returns:
      the builder.
    • notRetryOn

      public RetryTopicConfigurationBuilder notRetryOn(List<Class<? extends Throwable>> throwables)
      Configure the behavior to NOT retry on the provided Throwables.
      Parameters:
      throwables - the throwables.
      Returns:
      the builder.
    • traversingCauses

      public RetryTopicConfigurationBuilder traversingCauses()
      Configure the classifier to traverse the cause chain.
      Returns:
      the builder.
    • traversingCauses

      public RetryTopicConfigurationBuilder traversingCauses(boolean traversing)
      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

      Configure the container factory to use.
      Parameters:
      factory - the factory.
      Returns:
      the builder.
    • listenerFactory

      public RetryTopicConfigurationBuilder listenerFactory(@Nullable String factoryBeanName)
      Configure the container factory to use via its bean name.
      Parameters:
      factoryBeanName - the factory bean name.
      Returns:
      the builder.
    • create

      public RetryTopicConfiguration create(KafkaOperations<?,?> sendToTopicKafkaTemplate)
      Create the RetryTopicConfiguration with the provided template.
      Parameters:
      sendToTopicKafkaTemplate - the template.
      Returns:
      the configuration.
    • newInstance

      public static RetryTopicConfigurationBuilder newInstance()
      Create a new instance of the builder.
      Returns:
      the new instance.