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 Summary
ConstructorsConstructorDescriptionConstruct an instance with a defaultSimpleAsyncTaskExecutor.CommonContainerStoppingErrorHandler(Executor executor) Construct an instance with the providedExecutor. -
Method Summary
Modifier and TypeMethodDescriptionvoidhandleBatch(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.voidhandleOtherException(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.voidhandleRemaining(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 when#remainingRecords()returns true.booleanReturn 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).voidsetStopContainerAbnormally(boolean stopContainerAbnormally) Set to false to stop the container normally.Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel, setLogLevelMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.kafka.listener.CommonErrorHandler
clearThreadState, deliveryAttempt, deliveryAttemptHeader, handleBatchAndReturnRemaining, handleOne, isAckAfterHandle, logger, onPartitionsAssigned, setAckAfterHandle
-
Constructor Details
-
CommonContainerStoppingErrorHandler
public CommonContainerStoppingErrorHandler()Construct an instance with a defaultSimpleAsyncTaskExecutor. -
CommonContainerStoppingErrorHandler
Construct an instance with the providedExecutor.- 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 thatcontainer.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:CommonErrorHandlerReturn 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:
seeksAfterHandlingin interfaceCommonErrorHandler- 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:CommonErrorHandlerCalled when an exception is thrown with no records available, e.g. if the consumer poll throws an exception.- Specified by:
handleOtherExceptionin interfaceCommonErrorHandler- 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:CommonErrorHandlerHandle 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.- Specified by:
handleRemainingin interfaceCommonErrorHandler- Parameters:
thrownException- the exception.records- the remaining records including the one that failed.consumer- the consumer.container- the container.- See Also:
-
#remainingRecords()
-
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:CommonErrorHandlerHandle the exception for a batch listener. The completeConsumerRecordsfrom the poll is supplied. The error handler needs to perform seeks if you wish to reprocess the records in the batch.- Specified by:
handleBatchin interfaceCommonErrorHandler- Parameters:
thrownException- the exception.data- the consumer records.consumer- the consumer.container- the container.invokeListener- a callback to re-invoke the listener.
-