Interface CommonErrorHandler
- All Superinterfaces:
DeliveryAttemptAware
- All Known Implementing Classes:
CommonContainerStoppingErrorHandler,CommonDelegatingErrorHandler,CommonLoggingErrorHandler,CommonMixedErrorHandler,DefaultErrorHandler
Replacement for
ErrorHandler and BatchErrorHandler and their
sub-interfaces.- Since:
- 2.8
- Author:
- Gary Russell
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidOptional 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 booleanReturn true if this error handler supports delivery attempts headers.default voidhandleBatch(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener) Handle the exception for a batch listener.default <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K, V> handleBatchAndReturnRemaining(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener) Handle the exception for a batch listener.default booleanhandleOne(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 whenseeksAfterHandling()returns false.default voidhandleOtherException(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 voidhandleRemaining(Exception thrownException, List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container) Handle the exception for a record listener when#remainingRecords()returns true.default booleanReturn true if the offset should be committed for a handled error (no exception thrown).default LogAccessorlogger()Common error handler logger.default voidonPartitionsAssigned(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Collection<org.apache.kafka.common.TopicPartition> partitions, Runnable publishPause) Called when partitions are assigned.default booleanReturn 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 Details
-
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(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.
-
handleOne
default boolean handleOne(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 whenseeksAfterHandling()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:
-
handleRemaining
default void handleRemaining(Exception thrownException, List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container) Handle the exception for a record listener when#remainingRecords()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(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, 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.
-
logger
Common error handler logger.- Returns:
- the logger.
- Since:
- 3.1
-
handleBatchAndReturnRemaining
default <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> handleBatchAndReturnRemaining(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, 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
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
default void onPartitionsAssigned(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Collection<org.apache.kafka.common.TopicPartition> partitions, 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
-