Interface CommonErrorHandler
-
- All Superinterfaces:
DeliveryAttemptAware
- All Known Implementing Classes:
CommonContainerStoppingErrorHandler,CommonDelegatingErrorHandler,CommonLoggingErrorHandler,CommonMixedErrorHandler,DefaultErrorHandler
public interface CommonErrorHandler extends DeliveryAttemptAware
Replacement forErrorHandlerandBatchErrorHandlerand their sub-interfaces.- Since:
- 2.8
- Author:
- Gary Russell
-
-
Method Summary
All Methods Instance Methods Default Methods Deprecated Methods Modifier and Type Method Description default voidclearThreadState()Optional method to clear thread state; will be called just before a consumer thread terminates.default intdeliveryAttempt(TopicPartitionOffset topicPartitionOffset)Return the next delivery attempt for the topic/partition/offset.default booleandeliveryAttemptHeader()Return true if this error handler supports delivery attempts headers.default voidhandleBatch(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)Handle the exception for a batch listener.default <K,V>
org.apache.kafka.clients.consumer.ConsumerRecords<K,V>handleBatchAndReturnRemaining(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)Handle the exception for a batch listener.default booleanhandleOne(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)Handle the exception for a record listener whenremainingRecords()returns false.default voidhandleOtherException(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, boolean batchListener)Called when an exception is thrown with no records available, e.g.default voidhandleRecord(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)Deprecated.default voidhandleRemaining(java.lang.Exception thrownException, java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)Handle the exception for a record listener whenremainingRecords()returns true.default booleanisAckAfterHandle()Return true if the offset should be committed for a handled error (no exception thrown).default voidonPartitionsAssigned(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, java.util.Collection<org.apache.kafka.common.TopicPartition> partitions)Deprecated.in favor ofonPartitionsAssigned(Consumer, Collection, Runnable).default voidonPartitionsAssigned(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, java.util.Collection<org.apache.kafka.common.TopicPartition> partitions, java.lang.Runnable publishPause)Called when partitions are assigned.default booleanremainingRecords()Deprecated.in favor ofseeksAfterHandling().default booleanseeksAfterHandling()Return true if this error handler performs seeks on the failed record and remaining records (or just the remaining records after a failed record is recovered).default voidsetAckAfterHandle(boolean ack)Set to false to prevent the container from committing the offset of a recovered record (when the error handler does not itself throw an exception).
-
-
-
Method Detail
-
remainingRecords
@Deprecated default boolean remainingRecords()
Deprecated.in favor ofseeksAfterHandling().Return false if this error handler should only receive the current failed record; remaining records will be passed to the listener after the error handler returns. When true (default), all remaining records including the failed record are passed to the error handler.- Returns:
- false to receive only the failed record.
- See Also:
handleRecord(Exception, ConsumerRecord, Consumer, MessageListenerContainer),handleRemaining(Exception, List, Consumer, MessageListenerContainer)
-
seeksAfterHandling
default boolean seeksAfterHandling()
Return true if this error handler performs seeks on the failed record and remaining records (or just the remaining records after a failed record is recovered).- Returns:
- true if the next poll should fetch records.
-
deliveryAttemptHeader
default boolean deliveryAttemptHeader()
Return true if this error handler supports delivery attempts headers.- Returns:
- true if capable.
-
handleOtherException
default void handleOtherException(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, boolean batchListener)Called when an exception is thrown with no records available, e.g. if the consumer poll throws an exception.- Parameters:
thrownException- the exception.consumer- the consumer.container- the container.batchListener- true if the listener is a batch listener.
-
handleRecord
@Deprecated default void handleRecord(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)Deprecated.Handle the exception for a record listener whenremainingRecords()returns false. Use this to handle just the single failed record; remaining records from the poll will be sent to the listener.- Parameters:
thrownException- the exception.record- the record.consumer- the consumer.container- the container.- See Also:
remainingRecords()
-
handleOne
default boolean handleOne(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)Handle the exception for a record listener whenremainingRecords()returns false. Use this to handle just the single failed record.- Parameters:
thrownException- the exception.record- the record.consumer- the consumer.container- the container.- Returns:
- true if the error was "handled" or false if not and the container will re-submit the record to the listener.
- Since:
- 2.9
- See Also:
remainingRecords()
-
handleRemaining
default void handleRemaining(java.lang.Exception thrownException, java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)Handle the exception for a record listener whenremainingRecords()returns true. The failed record and all the remaining records from the poll are passed in. Usually used when the error handler performs seeks so that the remaining records will be redelivered on the next poll.- Parameters:
thrownException- the exception.records- the remaining records including the one that failed.consumer- the consumer.container- the container.- See Also:
remainingRecords()
-
handleBatch
default void handleBatch(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)Handle the exception for a batch listener. The completeConsumerRecordsfrom the poll is supplied. The error handler needs to perform seeks if you wish to reprocess the records in the batch.- Parameters:
thrownException- the exception.data- the consumer records.consumer- the consumer.container- the container.invokeListener- a callback to re-invoke the listener.
-
handleBatchAndReturnRemaining
default <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> handleBatchAndReturnRemaining(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)Handle the exception for a batch listener. The completeConsumerRecordsfrom the poll is supplied. Return the members of the batch that should be re-sent to the listener. The returned records MUST be in the same order as the original records.- Type Parameters:
K- the key type.V- the value type.- Parameters:
thrownException- the exception.data- the consumer records.consumer- the consumer.container- the container.invokeListener- a callback to re-invoke the listener.- Returns:
- the consumer records, or a subset.
- Since:
- 2.9
-
deliveryAttempt
default int deliveryAttempt(TopicPartitionOffset topicPartitionOffset)
Description copied from interface:DeliveryAttemptAwareReturn the next delivery attempt for the topic/partition/offset.- Specified by:
deliveryAttemptin interfaceDeliveryAttemptAware- Parameters:
topicPartitionOffset- the topic/partition/offset.- Returns:
- the next delivery attempt.
-
clearThreadState
default void clearThreadState()
Optional method to clear thread state; will be called just before a consumer thread terminates.
-
isAckAfterHandle
default boolean isAckAfterHandle()
Return true if the offset should be committed for a handled error (no exception thrown).- Returns:
- true to commit.
-
setAckAfterHandle
default void setAckAfterHandle(boolean ack)
Set to false to prevent the container from committing the offset of a recovered record (when the error handler does not itself throw an exception).- Parameters:
ack- false to not commit.
-
onPartitionsAssigned
@Deprecated default void onPartitionsAssigned(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, java.util.Collection<org.apache.kafka.common.TopicPartition> partitions)Deprecated.in favor ofonPartitionsAssigned(Consumer, Collection, Runnable).Called when partitions are assigned.- Parameters:
consumer- the consumer.partitions- the newly assigned partitions.- Since:
- 2.8.8
-
onPartitionsAssigned
default void onPartitionsAssigned(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, java.util.Collection<org.apache.kafka.common.TopicPartition> partitions, java.lang.Runnable publishPause)Called when partitions are assigned.- Parameters:
consumer- the consumer.partitions- the newly assigned partitions.publishPause- called to publish a consumer paused event.- Since:
- 2.8.9
-
-