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 void
Optional method to clear thread state; will be called just before a consumer thread terminates.default int
deliveryAttempt
(TopicPartitionOffset topicPartitionOffset) Return the next delivery attempt for the topic/partition/offset.default boolean
Return true if this error handler supports delivery attempts headers.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.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 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 whenremainingRecords()
returns false.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.default void
handleRecord
(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container) Deprecated, for removal: This API element is subject to removal in a future version.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 whenremainingRecords()
returns true.default boolean
Return true if the offset should be committed for a handled error (no exception thrown).default void
onPartitionsAssigned
(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Collection<org.apache.kafka.common.TopicPartition> partitions, Runnable publishPause) Called when partitions are assigned.default boolean
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofseeksAfterHandling()
.default boolean
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 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).
-
Method Details
-
remainingRecords
Deprecated, for removal: This API element is subject to removal in a future version.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:
-
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.
-
handleRecord
@Deprecated(since="2.9", forRemoval=true) default void handleRecord(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container) Deprecated, for removal: This API element is subject to removal in a future version.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:
-
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 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:
-
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 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:
-
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 completeConsumerRecords
from 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(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 completeConsumerRecords
from 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:DeliveryAttemptAware
Return the next delivery attempt for the topic/partition/offset.- Specified by:
deliveryAttempt
in 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
-
handleOne(Exception, ConsumerRecord, Consumer, MessageListenerContainer)
.