Class CommonContainerStoppingErrorHandler

java.lang.Object
org.springframework.kafka.listener.KafkaExceptionLogLevelAware
org.springframework.kafka.listener.CommonContainerStoppingErrorHandler
All Implemented Interfaces:
CommonErrorHandler, DeliveryAttemptAware

public class CommonContainerStoppingErrorHandler extends KafkaExceptionLogLevelAware implements CommonErrorHandler
A CommonErrorHandler that stops the container when an error occurs. Replaces the legacy ContainerStoppingErrorHandler and ContainerStoppingBatchErrorHandler.
Since:
2.8
Author:
Gary Russell
  • Constructor Details

    • CommonContainerStoppingErrorHandler

      public CommonContainerStoppingErrorHandler()
      Construct an instance with a default SimpleAsyncTaskExecutor.
    • CommonContainerStoppingErrorHandler

      public CommonContainerStoppingErrorHandler(Executor executor)
      Construct an instance with the provided Executor.
      Parameters:
      executor - the executor.
  • Method Details

    • setStopContainerAbnormally

      public void setStopContainerAbnormally(boolean stopContainerAbnormally)
      Set to false to stop the container normally. By default, the container is stopped abnormally, so that container.isInExpectedState() returns false. If you want to container to remain "healthy" when using this error handler, set the property to false.
      Parameters:
      stopContainerAbnormally - false for normal stop.
      Since:
      2.8
    • 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.
    • handleOtherException

      public void handleOtherException(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.
    • handleRemaining

      public void handleRemaining(Exception thrownException, 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.seeksAfterHandling() 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:
    • handleBatch

      public void handleBatch(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, 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.