Class DefaultAfterRollbackProcessor<K,V>
- java.lang.Object
-
- org.springframework.kafka.listener.KafkaExceptionLogLevelAware
-
- org.springframework.kafka.listener.FailedRecordProcessor
-
- org.springframework.kafka.listener.DefaultAfterRollbackProcessor<K,V>
-
- Type Parameters:
K- the key type.V- the value type.
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean,AfterRollbackProcessor<K,V>,DeliveryAttemptAware
public class DefaultAfterRollbackProcessor<K,V> extends FailedRecordProcessor implements AfterRollbackProcessor<K,V>, org.springframework.beans.factory.InitializingBean
Default implementation ofAfterRollbackProcessor. Seeks all topic/partitions so the records will be re-fetched, including the failed record. Starting with version 2.2 after a configurable number of failures for the same topic/partition/offset, that record will be skipped after calling aBiConsumerrecoverer. The default recoverer simply logs the failed record.- Since:
- 1.3.5
- Author:
- Gary Russell
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.listener.FailedRecordProcessor
logger
-
-
Constructor Summary
Constructors Constructor Description DefaultAfterRollbackProcessor()Construct an instance with the default recoverer which simply logs the record after 10 (maxFailures) have occurred for a topic/partition/offset.DefaultAfterRollbackProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer)Construct an instance with the provided recoverer which will be called after 10 (maxFailures) have occurred for a topic/partition/offset.DefaultAfterRollbackProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff)Construct an instance with the provided recoverer which will be called after the backOff returns STOP for a topic/partition/offset.DefaultAfterRollbackProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff, KafkaOperations<?,?> kafkaOperations, boolean commitRecovered)Construct an instance with the provided recoverer which will be called after the backOff returns STOP for a topic/partition/offset.DefaultAfterRollbackProcessor(org.springframework.util.backoff.BackOff backOff)Construct an instance with the default recoverer which simply logs the record after the backOff returns STOP for a topic/partition/offset.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidafterPropertiesSet()booleanisProcessInTransaction()Return true to invokeAfterRollbackProcessor.process(List, Consumer, Exception, boolean, ContainerProperties.EOSMode)in a new transaction.voidprocess(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> records, org.apache.kafka.clients.consumer.Consumer<K,V> consumer, java.lang.Exception exception, boolean recoverable)Deprecated.voidprocess(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> records, org.apache.kafka.clients.consumer.Consumer<K,V> consumer, java.lang.Exception exception, boolean recoverable, ContainerProperties.EOSMode eosMode)Process the remaining records.voidsetCommitRecovered(boolean commitRecovered)Deprecated.voidsetKafkaOperations(KafkaOperations<K,V> kafkaOperations)Deprecated.voidsetKafkaTemplate(KafkaTemplate<K,V> kafkaTemplate)Deprecated.-
Methods inherited from class org.springframework.kafka.listener.FailedRecordProcessor
addNotRetryableException, addNotRetryableExceptions, clearThreadState, deliveryAttempt, getClassifier, getSkipPredicate, isCommitRecovered, removeNotRetryableException, setBackOffFunction, setClassifications, setResetStateOnRecoveryFailure
-
Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel, setLogLevel
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.kafka.listener.AfterRollbackProcessor
clearThreadState
-
-
-
-
Constructor Detail
-
DefaultAfterRollbackProcessor
public DefaultAfterRollbackProcessor()
Construct an instance with the default recoverer which simply logs the record after 10 (maxFailures) have occurred for a topic/partition/offset.- Since:
- 2.2
-
DefaultAfterRollbackProcessor
public DefaultAfterRollbackProcessor(org.springframework.util.backoff.BackOff backOff)
Construct an instance with the default recoverer which simply logs the record after the backOff returns STOP for a topic/partition/offset.- Parameters:
backOff- theBackOff.- Since:
- 2.3
-
DefaultAfterRollbackProcessor
public DefaultAfterRollbackProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer)
Construct an instance with the provided recoverer which will be called after 10 (maxFailures) have occurred for a topic/partition/offset.- Parameters:
recoverer- the recoverer.- Since:
- 2.2
-
DefaultAfterRollbackProcessor
public DefaultAfterRollbackProcessor(@Nullable java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff)Construct an instance with the provided recoverer which will be called after the backOff returns STOP for a topic/partition/offset.- Parameters:
recoverer- the recoverer; if null, the default (logging) recoverer is used.backOff- theBackOff.- Since:
- 2.3
-
DefaultAfterRollbackProcessor
public DefaultAfterRollbackProcessor(@Nullable java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff, @Nullable KafkaOperations<?,?> kafkaOperations, boolean commitRecovered)Construct an instance with the provided recoverer which will be called after the backOff returns STOP for a topic/partition/offset.- Parameters:
recoverer- the recoverer; if null, the default (logging) recoverer is used.backOff- theBackOff.kafkaOperations- for sending the recovered offset to the transaction.commitRecovered- true to commit the recovered record's offset; requires aKafkaOperations.- Since:
- 2.5.3
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
process
@Deprecated public void process(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> records, org.apache.kafka.clients.consumer.Consumer<K,V> consumer, java.lang.Exception exception, boolean recoverable)
Deprecated.Description copied from interface:AfterRollbackProcessorProcess the remaining records. Recoverable will be true if the container is processing individual records; this allows the processor to recover (skip) the failed record rather than re-seeking it. This is not possible with a batch listener since only the listener itself knows which record in the batch keeps failing. IMPORTANT: If invoked in a transaction when the listener was invoked with a single record, the transaction id will be based on the container group.id and the topic/partition of the failed record, to avoid issues with zombie fencing. So, generally, only its offset should be sent to the transaction. For other behavior the process method should manage its own transaction.- Specified by:
processin interfaceAfterRollbackProcessor<K,V>- Parameters:
records- the records.consumer- the consumer.exception- the exceptionrecoverable- the recoverable.- See Also:
AfterRollbackProcessor.isProcessInTransaction()
-
process
public void process(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> records, org.apache.kafka.clients.consumer.Consumer<K,V> consumer, java.lang.Exception exception, boolean recoverable, @Nullable ContainerProperties.EOSMode eosMode)
Description copied from interface:AfterRollbackProcessorProcess the remaining records. Recoverable will be true if the container is processing individual records; this allows the processor to recover (skip) the failed record rather than re-seeking it. This is not possible with a batch listener since only the listener itself knows which record in the batch keeps failing. IMPORTANT: If invoked in a transaction when the listener was invoked with a single record, the transaction id will be based on the container group.id and the topic/partition of the failed record, to avoid issues with zombie fencing (unless theContainerProperties.EOSModeisContainerProperties.EOSMode.BETA). So, generally, only its offset should be sent to the transaction. For other behavior the process method should manage its own transaction.- Specified by:
processin interfaceAfterRollbackProcessor<K,V>- Parameters:
records- the records.consumer- the consumer.exception- the exceptionrecoverable- the recoverable.eosMode- theContainerProperties.EOSMode.- See Also:
AfterRollbackProcessor.isProcessInTransaction()
-
isProcessInTransaction
public boolean isProcessInTransaction()
Description copied from interface:AfterRollbackProcessorReturn true to invokeAfterRollbackProcessor.process(List, Consumer, Exception, boolean, ContainerProperties.EOSMode)in a new transaction. Because the container cannot infer the desired behavior, the processor is responsible for sending the offset to the transaction if it decides to skip the failing record.- Specified by:
isProcessInTransactionin interfaceAfterRollbackProcessor<K,V>- Returns:
- true to run in a transaction; default false.
- See Also:
AfterRollbackProcessor.process(List, Consumer, Exception, boolean, ContainerProperties.EOSMode)
-
setCommitRecovered
@Deprecated public void setCommitRecovered(boolean commitRecovered)
Deprecated.Set to true to commit the offset for a recovered record. Set to true and the container will run theprocess(List, Consumer, Exception, boolean, ContainerProperties.EOSMode)method in a transaction and, if a record is skipped and recovered, we will send its offset to the transaction. Requires aKafkaOperations.- Overrides:
setCommitRecoveredin classFailedRecordProcessor- Parameters:
commitRecovered- true to process in a transaction.- Since:
- 2.3
- See Also:
isProcessInTransaction(),process(List, Consumer, Exception, boolean, ContainerProperties.EOSMode)
-
setKafkaTemplate
@Deprecated public void setKafkaTemplate(KafkaTemplate<K,V> kafkaTemplate)
Deprecated.Set aKafkaTemplateto use to send the offset of a recovered record to a transaction.- Parameters:
kafkaTemplate- the template.- Since:
- 2.2.5
- See Also:
setCommitRecovered(boolean)
-
setKafkaOperations
@Deprecated public void setKafkaOperations(KafkaOperations<K,V> kafkaOperations)
Deprecated.Set aKafkaOperationsto use to send the offset of a recovered record to a transaction.- Parameters:
kafkaOperations- the operations.- Since:
- 2.5.1
- See Also:
setCommitRecovered(boolean)
-
-