Class CommonMixedErrorHandler

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearThreadState()
      Optional method to clear thread state; will be called just before a consumer thread terminates.
      int deliveryAttempt​(TopicPartitionOffset topicPartitionOffset)
      Return the next delivery attempt for the topic/partition/offset.
      boolean deliveryAttemptHeader()
      Return true if this error handler supports delivery attempts headers.
      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.
      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 CommonErrorHandler.remainingRecords() returns false.
      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.
      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 CommonErrorHandler.remainingRecords() returns true.
      boolean isAckAfterHandle()
      Return true if the offset should be committed for a handled error (no exception thrown).
      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.
      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).
      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).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CommonMixedErrorHandler

        public CommonMixedErrorHandler​(CommonErrorHandler recordErrorHandler,
                                       CommonErrorHandler batchErrorHandler)
        Construct an instance with the provided delegate CommonErrorHandlers.
        Parameters:
        recordErrorHandler - the error handler for record listeners.
        batchErrorHandler - the error handler for batch listeners.
    • Method Detail

      • seeksAfterHandling

        public boolean seeksAfterHandling()
        Description copied from interface: CommonErrorHandler
        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).
        Specified by:
        seeksAfterHandling in interface CommonErrorHandler
        Returns:
        true if the next poll should fetch records.
      • deliveryAttemptHeader

        public boolean deliveryAttemptHeader()
        Description copied from interface: CommonErrorHandler
        Return true if this error handler supports delivery attempts headers.
        Specified by:
        deliveryAttemptHeader in interface CommonErrorHandler
        Returns:
        true if capable.
      • handleOtherException

        public void handleOtherException​(java.lang.Exception thrownException,
                                         org.apache.kafka.clients.consumer.Consumer<?,​?> consumer,
                                         MessageListenerContainer container,
                                         boolean batchListener)
        Description copied from interface: CommonErrorHandler
        Called when an exception is thrown with no records available, e.g. if the consumer poll throws an exception.
        Specified by:
        handleOtherException in interface CommonErrorHandler
        Parameters:
        thrownException - the exception.
        consumer - the consumer.
        container - the container.
        batchListener - true if the listener is a batch listener.
      • handleOne

        public boolean handleOne​(java.lang.Exception thrownException,
                                 org.apache.kafka.clients.consumer.ConsumerRecord<?,​?> record,
                                 org.apache.kafka.clients.consumer.Consumer<?,​?> consumer,
                                 MessageListenerContainer container)
        Description copied from interface: CommonErrorHandler
        Handle the exception for a record listener when CommonErrorHandler.remainingRecords() returns false. Use this to handle just the single failed record.
        Specified by:
        handleOne in interface CommonErrorHandler
        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.
        See Also:
        CommonErrorHandler.remainingRecords()
      • handleRemaining

        public 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)
        Description copied from interface: CommonErrorHandler
        Handle the exception for a record listener when CommonErrorHandler.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.
        Specified by:
        handleRemaining in interface CommonErrorHandler
        Parameters:
        thrownException - the exception.
        records - the remaining records including the one that failed.
        consumer - the consumer.
        container - the container.
        See Also:
        CommonErrorHandler.remainingRecords()
      • handleBatch

        public 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)
        Description copied from interface: CommonErrorHandler
        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.
        Specified by:
        handleBatch in interface CommonErrorHandler
        Parameters:
        thrownException - the exception.
        data - the consumer records.
        consumer - the consumer.
        container - the container.
        invokeListener - a callback to re-invoke the listener.
      • clearThreadState

        public void clearThreadState()
        Description copied from interface: CommonErrorHandler
        Optional method to clear thread state; will be called just before a consumer thread terminates.
        Specified by:
        clearThreadState in interface CommonErrorHandler
      • isAckAfterHandle

        public boolean isAckAfterHandle()
        Description copied from interface: CommonErrorHandler
        Return true if the offset should be committed for a handled error (no exception thrown).
        Specified by:
        isAckAfterHandle in interface CommonErrorHandler
        Returns:
        true to commit.
      • setAckAfterHandle

        public void setAckAfterHandle​(boolean ack)
        Description copied from interface: CommonErrorHandler
        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).
        Specified by:
        setAckAfterHandle in interface CommonErrorHandler
        Parameters:
        ack - false to not commit.