Interface CommonErrorHandler

    • Method Summary

      All Methods Instance Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default void clearThreadState()
      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 deliveryAttemptHeader()
      Return true if this error handler supports delivery attempts headers.
      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.
      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 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 when remainingRecords() returns false.
      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.
      default void handleRecord​(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?,​?> record, org.apache.kafka.clients.consumer.Consumer<?,​?> consumer, MessageListenerContainer container)
      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 when remainingRecords() returns true.
      default boolean isAckAfterHandle()
      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, java.util.Collection<org.apache.kafka.common.TopicPartition> partitions)
      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.
      default boolean remainingRecords()
      Deprecated.
      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).
      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 Detail

      • 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)
        Handle the exception for a record listener when remainingRecords() 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 when remainingRecords() 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 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​(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 complete ConsumerRecords 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​(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 complete ConsumerRecords 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

        default int deliveryAttempt​(TopicPartitionOffset topicPartitionOffset)
        Description copied from interface: DeliveryAttemptAware
        Return the next delivery attempt for the topic/partition/offset.
        Specified by:
        deliveryAttempt in interface DeliveryAttemptAware
        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)
        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