Class DeadLetterPublishingRecovererFactory
java.lang.Object
org.springframework.kafka.retrytopic.DeadLetterPublishingRecovererFactory
Creates and configures the
DeadLetterPublishingRecoverer
that will be used to
forward the messages using the DestinationTopicResolver
.- Since:
- 2.7
- Author:
- Tomaz Fernandes, Gary Russell
-
Constructor Summary
ConstructorDescriptionDeadLetterPublishingRecovererFactory
(DestinationTopicResolver destinationTopicResolver) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addNotRetryableException
(Class<? extends Exception> exceptionType) Add exception type to the default list.create()
boolean
removeNotRetryableException
(Class<? extends 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
void
setHeadersFunction
(BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, 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.
-
Constructor Details
-
DeadLetterPublishingRecovererFactory
-
-
Method Details
-
setHeadersFunction
public void setHeadersFunction(BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, 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
-
addNotRetryableException
Add exception type to the default list. By default, the following exceptions will not be retried: All others will be retried.- Parameters:
exceptionType
- the exception type.- Since:
- 2.8
- See Also:
-
removeNotRetryableException
Remove an exception type from the configured list. By default, the following exceptions will not be retried: All others will be retried.- Parameters:
exceptionType
- the exception type.- Returns:
- true if the removal was successful.
- See Also:
-
create
-
setDeadLetterPublishingRecovererCustomizer
public void setDeadLetterPublishingRecovererCustomizer(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.
- 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
-