K - the key type.V - the value type.public class DefaultAfterRollbackProcessor<K,V> extends java.lang.Object implements AfterRollbackProcessor<K,V>
AfterRollbackProcessor. 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 a BiConsumer recoverer. The default recoverer simply logs
the failed record.| Constructor and Description |
|---|
DefaultAfterRollbackProcessor()
Construct an instance with the default recoverer which simply logs the record after
(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
(maxFailures) have occurred for a
topic/partition/offset.
|
DefaultAfterRollbackProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer,
int maxFailures)
Construct an instance with the provided recoverer which will be called after
maxFailures have occurred for a topic/partition/offset.
|
DefaultAfterRollbackProcessor(int maxFailures)
Construct an instance with the default recoverer which simply logs the record after
'maxFailures' have occurred for a topic/partition/offset.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearThreadState()
Optional method to clear thread state; will be called just before a consumer
thread terminates.
|
boolean |
isProcessInTransaction()
Return true to invoke
AfterRollbackProcessor.process(List, Consumer, Exception, boolean) in a new
transaction. |
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)
Process the remaining records.
|
void |
setKafkaTemplate(KafkaTemplate<K,V> kafkaTemplate)
Set a
KafkaTemplate to use to send the offset of a recovered record
to a transaction. |
void |
setProcessInTransaction(boolean processInTransaction)
Set to true to run the
process(List, Consumer, Exception, boolean)
method in a transaction. |
public DefaultAfterRollbackProcessor()
public DefaultAfterRollbackProcessor(int maxFailures)
maxFailures - the maxFailures; a negative value is treated as infinity.public DefaultAfterRollbackProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer)
recoverer - the recoverer.public DefaultAfterRollbackProcessor(@Nullable
java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer,
int maxFailures)
recoverer - the recoverer; if null, the default (logging) recoverer is used.maxFailures - the maxFailures; a negative value is treated as infinity.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)
AfterRollbackProcessorprocess in interface AfterRollbackProcessor<K,V>records - the records.consumer - the consumer.exception - the exceptionrecoverable - the recoverable.AfterRollbackProcessor.isProcessInTransaction()public boolean isProcessInTransaction()
AfterRollbackProcessorAfterRollbackProcessor.process(List, Consumer, Exception, boolean) 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.isProcessInTransaction in interface AfterRollbackProcessor<K,V>AfterRollbackProcessor.process(List, Consumer, Exception, boolean)public void setProcessInTransaction(boolean processInTransaction)
process(List, Consumer, Exception, boolean)
method in a transaction. Requires a KafkaTemplate.processInTransaction - true to process in a transaction.process(List, Consumer, Exception, boolean),
setKafkaTemplate(KafkaTemplate)public void setKafkaTemplate(KafkaTemplate<K,V> kafkaTemplate)
KafkaTemplate to use to send the offset of a recovered record
to a transaction.kafkaTemplate - the templatesetProcessInTransaction(boolean)public void clearThreadState()
AfterRollbackProcessorclearThreadState in interface AfterRollbackProcessor<K,V>