K
- the key type.V
- the value type.public class DefaultAfterRollbackProcessor<K,V> extends FailedRecordProcessor 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.logger
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(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.
|
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,
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,
int maxFailures)
Deprecated.
in favor of
DefaultAfterRollbackProcessor(BackOff) .
IMPORTANT When using a
FixedBackOff , the maxAttempts property
represents retries (one less than maxFailures). To retry indefinitely, use a fixed
or exponential BackOff configured appropriately. To use the other
constructor with the semantics of this one, with maxFailures equal to 3, use
new DefaultAfterRollbackProcessor(recoverer, new FixedBackOff(0L, 2L) . |
DefaultAfterRollbackProcessor(int maxFailures)
Deprecated.
in favor of
DefaultAfterRollbackProcessor(BackOff) .
IMPORTANT When using a
FixedBackOff , the maxAttempts property
represents retries (one less than maxFailures). To retry indefinitely, use a fixed
or exponential BackOff configured appropriately. To use the other
constructor with the semantics of this one, with maxFailures equal to 3, use
new DefaultAfterRollbackProcessor(new FixedBackOff(0L, 2L) . |
Modifier and Type | Method and Description |
---|---|
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 |
setCommitRecovered(boolean commitRecovered)
Set to true to commit the offset for a recovered record.
|
void |
setKafkaTemplate(KafkaTemplate<K,V> kafkaTemplate)
Set a
KafkaTemplate to use to send the offset of a recovered record
to a transaction. |
addNotRetryableException, clearThreadState, getClassifier, getSkipPredicate, isCommitRecovered, removeNotRetryableException, setClassifications, setClassifier
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearThreadState
public DefaultAfterRollbackProcessor()
@Deprecated public DefaultAfterRollbackProcessor(int maxFailures)
DefaultAfterRollbackProcessor(BackOff)
.
IMPORTANT When using a
FixedBackOff
, the maxAttempts property
represents retries (one less than maxFailures). To retry indefinitely, use a fixed
or exponential BackOff
configured appropriately. To use the other
constructor with the semantics of this one, with maxFailures equal to 3, use
new DefaultAfterRollbackProcessor(new FixedBackOff(0L, 2L)
.maxFailures
- the maxFailures; a negative value is treated as infinity.public DefaultAfterRollbackProcessor(org.springframework.util.backoff.BackOff backOff)
backOff
- the BackOff
.public DefaultAfterRollbackProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer)
recoverer
- the recoverer.@Deprecated public DefaultAfterRollbackProcessor(@Nullable java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, int maxFailures)
DefaultAfterRollbackProcessor(BackOff)
.
IMPORTANT When using a
FixedBackOff
, the maxAttempts property
represents retries (one less than maxFailures). To retry indefinitely, use a fixed
or exponential BackOff
configured appropriately. To use the other
constructor with the semantics of this one, with maxFailures equal to 3, use
new DefaultAfterRollbackProcessor(recoverer, new FixedBackOff(0L, 2L)
.recoverer
- the recoverer; if null, the default (logging) recoverer is used.maxFailures
- the maxFailures; a negative value is treated as infinity.public DefaultAfterRollbackProcessor(@Nullable java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff)
recoverer
- the recoverer; if null, the default (logging) recoverer is used.backOff
- the BackOff
.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)
AfterRollbackProcessor
process
in interface AfterRollbackProcessor<K,V>
records
- the records.consumer
- the consumer.exception
- the exceptionrecoverable
- the recoverable.AfterRollbackProcessor.isProcessInTransaction()
public boolean isProcessInTransaction()
AfterRollbackProcessor
AfterRollbackProcessor.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 setCommitRecovered(boolean commitRecovered)
process(List, Consumer, Exception, boolean)
method in a transaction and,
if a record is skipped and recovered, we will send its offset to the transaction.
Requires a KafkaTemplate
.setCommitRecovered
in class FailedRecordProcessor
commitRecovered
- true to process in a transaction.isProcessInTransaction()
,
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 templatesetCommitRecovered(boolean)