Interface CommonErrorHandler

    • Method Summary

      All Methods Instance Methods Default 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 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)
      Handle the exception for a record listener when remainingRecords() returns false.
      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)
      Called when partitions are assigned.
      default boolean remainingRecords()
      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.
      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

      • 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

        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()
      • 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.
      • 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

        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