Class DeadLetterPublishingRecovererFactory
- java.lang.Object
-
- org.springframework.kafka.retrytopic.DeadLetterPublishingRecovererFactory
-
public class DeadLetterPublishingRecovererFactory extends java.lang.Object
Creates and configures theDeadLetterPublishingRecoverer
that will be used to forward the messages using theDestinationTopicResolver
.- Since:
- 2.7
- Author:
- Tomaz Fernandes, Gary Russell
-
-
Constructor Summary
Constructors Constructor Description DeadLetterPublishingRecovererFactory(DestinationTopicResolver destinationTopicResolver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNotRetryableException(java.lang.Class<? extends java.lang.Exception> exceptionType)
Add exception type to the default list.void
alwaysLogListenerException()
Logs the listener exception at each attempt.DeadLetterPublishingRecoverer
create()
void
neverLogListenerException()
Never logs the listener exception.boolean
removeNotRetryableException(java.lang.Class<? extends java.lang.Exception> exceptionType)
Remove an exception type from the configured list.protected org.apache.kafka.common.TopicPartition
resolveTopicPartition(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> cr, DestinationTopic nextDestination)
Creates and returns theTopicPartition
, where the original record should be forwarded.void
setDeadLetterPublishingRecovererCustomizer(java.util.function.Consumer<DeadLetterPublishingRecoverer> customizer)
void
setHeadersFunction(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception,org.apache.kafka.common.header.Headers> headersFunction)
Set a function that creates additional headers for the output record, in addition to the standard retry headers added by this factory.void
setPartitionResolver(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.String,java.lang.Integer> resolver)
Set a resolver for the partition number to publish to.void
setRetainAllRetryHeaderValues(boolean retainAllRetryHeaderValues)
Set to false to only retain the last value forRetryTopicHeaders
; true by default, which retains all the values as the record transitions through topics.
-
-
-
Constructor Detail
-
DeadLetterPublishingRecovererFactory
public DeadLetterPublishingRecovererFactory(DestinationTopicResolver destinationTopicResolver)
-
-
Method Detail
-
setHeadersFunction
public void setHeadersFunction(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception,org.apache.kafka.common.header.Headers> headersFunction)
Set a function that creates additional headers for the output record, in addition to the standard retry headers added by this factory.- Parameters:
headersFunction
- the function.- Since:
- 2.8.4
-
setPartitionResolver
public void setPartitionResolver(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.String,java.lang.Integer> resolver)
Set a resolver for the partition number to publish to. By default the same partition as the consumer record is used. If the resolver returnsnull
or a negative number, the partition is set to null in the producer record and theKafkaProducer
decides which partition to publish to.- Parameters:
resolver
- the resolver.- Since:
- 2.9.2
-
setRetainAllRetryHeaderValues
public void setRetainAllRetryHeaderValues(boolean retainAllRetryHeaderValues)
Set to false to only retain the last value forRetryTopicHeaders
; true by default, which retains all the values as the record transitions through topics.- Parameters:
retainAllRetryHeaderValues
- false to only store the last values.- Since:
- 2.9.6
-
addNotRetryableException
public final void addNotRetryableException(java.lang.Class<? extends java.lang.Exception> exceptionType)
Add exception type to the default list. By default, the following exceptions will not be retried:DeserializationException
MessageConversionException
ConversionException
MethodArgumentResolutionException
NoSuchMethodException
ClassCastException
- Parameters:
exceptionType
- the exception type.- Since:
- 2.8
- See Also:
removeNotRetryableException(Class)
-
removeNotRetryableException
public boolean removeNotRetryableException(java.lang.Class<? extends java.lang.Exception> exceptionType)
Remove an exception type from the configured list. By default, the following exceptions will not be retried:DeserializationException
MessageConversionException
ConversionException
MethodArgumentResolutionException
NoSuchMethodException
ClassCastException
- Parameters:
exceptionType
- the exception type.- Returns:
- true if the removal was successful.
- See Also:
addNotRetryableException(Class)
-
neverLogListenerException
public void neverLogListenerException()
Never logs the listener exception. The default is logging only after retries are exhausted.- Since:
- 2.7.13
-
alwaysLogListenerException
public void alwaysLogListenerException()
Logs the listener exception at each attempt. The default is logging only after retries are exhausted.- Since:
- 2.7.13
-
create
public DeadLetterPublishingRecoverer create()
-
setDeadLetterPublishingRecovererCustomizer
public void setDeadLetterPublishingRecovererCustomizer(java.util.function.Consumer<DeadLetterPublishingRecoverer> customizer)
-
resolveTopicPartition
protected org.apache.kafka.common.TopicPartition resolveTopicPartition(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> cr, DestinationTopic nextDestination)
Creates and returns theTopicPartition
, where the original record should be forwarded. By default, it will use the partition same as original record's partition, in the next destination topic.DeadLetterPublishingRecoverer.checkPartition(org.apache.kafka.common.TopicPartition, org.apache.kafka.clients.consumer.Consumer<?, ?>)
has logic to check whether that partition exists, and if it doesn't it sets -1, to allow the Producer itself to assign a partition to the record.Subclasses can inherit from this method to override the implementation, if necessary.
The destination partition can also be customized usingsetPartitionResolver(BiFunction)
.- Parameters:
cr
- The originalConsumerRecord
, which is to be forwarded to DLTnextDestination
- The nextDestinationTopic
, where the consumerRecord is to be forwarded- Returns:
- An instance of
TopicPartition
, specifying the topic and partition, where the cr is to be sent. - See Also:
setPartitionResolver(BiFunction)
-
-