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, Soby Chacko, Artem Bilan
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceImplement this interface to create eachDeadLetterPublishingRecoverer. -
Constructor Summary
ConstructorsConstructorDescriptionDeadLetterPublishingRecovererFactory(DestinationTopicResolver destinationTopicResolver) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddNotRetryableException(Class<? extends Exception> exceptionType) Add an exception type to the default list.voidLogs the listener exception at each attempt.protected voidmaybeLogListenerException(Exception exception, org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> consumerRecord, DestinationTopic nextDestination) Log the exception before sending the record in error to the retry topic.voidNever logs the listener exception.booleanremoveNotRetryableException(Class<? extends Exception> exceptionType) Remove an exception type from the configured list.protected org.apache.kafka.common.TopicPartitionresolveTopicPartition(org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> cr, DestinationTopic nextDestination) Creates and returns theTopicPartition, where the original record should be forwarded.voidsetDeadLetterPublisherCreator(DeadLetterPublishingRecovererFactory.DeadLetterPublisherCreator creator) Provide aDeadLetterPublishingRecovererFactory.DeadLetterPublisherCreator; used to create a subclass of theDeadLetterPublishingRecoverer, instead of the default, for example, to modify the published records.voidSet a customizer to customize the defaultDeadLetterPublishingRecoverer.voidsetHeadersFunction(BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception, @Nullable 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.voidsetPartitionResolver(BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, @Nullable String, @Nullable Integer> resolver) Set a resolver for the partition number to publish to.voidsetRetainAllRetryHeaderValues(boolean retainAllRetryHeaderValues) Set tofalseto only retain the last value forRetryTopicHeaders; true by default, which retains all the values as the record transitions through topics.
-
Constructor Details
-
DeadLetterPublishingRecovererFactory
-
-
Method Details
-
setHeadersFunction
public void setHeadersFunction(BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception, @Nullable 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(BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, @Nullable String, @Nullable 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 returnsnullor a negative number, the partition is set to null in the producer record and theKafkaProducerdecides which partition to publish to.- Parameters:
resolver- the resolver.- Since:
- 2.9.2
-
setRetainAllRetryHeaderValues
public void setRetainAllRetryHeaderValues(boolean retainAllRetryHeaderValues) Set tofalseto 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
-
setDeadLetterPublisherCreator
public void setDeadLetterPublisherCreator(DeadLetterPublishingRecovererFactory.DeadLetterPublisherCreator creator) Provide aDeadLetterPublishingRecovererFactory.DeadLetterPublisherCreator; used to create a subclass of theDeadLetterPublishingRecoverer, instead of the default, for example, to modify the published records.- Parameters:
creator- the creator,- Since:
- 3.0.9.
-
setDeadLetterPublishingRecovererCustomizer
public void setDeadLetterPublishingRecovererCustomizer(Consumer<DeadLetterPublishingRecoverer> customizer) Set a customizer to customize the defaultDeadLetterPublishingRecoverer.- Parameters:
customizer- the customizer.- See Also:
-
addNotRetryableException
Add an 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:
-
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
-
maybeLogListenerException
protected void maybeLogListenerException(Exception exception, org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> consumerRecord, DestinationTopic nextDestination) Log the exception before sending the record in error to the retry topic. This method can be overridden by downstream applications to customize how the error is logged.- Parameters:
exception- the exception that caused the errorconsumerRecord- the original consumer recordnextDestination- the next topic where the record goes- Since:
- 3.3.0
-
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 same partition as the original record's partition, in the next destination topic.DeadLetterPublishingRecoverer#checkPartitionhas 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:
-