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 TypeMethodDescriptionvoid
handleBatch
(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.void
handleOtherException
(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
(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 whenCommonErrorHandler.remainingRecords()
returns true.boolean
Deprecated, for removal: This API element is subject to removal in a future version.boolean
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
setStopContainerAbnormally
(boolean stopContainerAbnormally) Set to false to stop the container normally.Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel, setLogLevel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.kafka.listener.CommonErrorHandler
clearThreadState, deliveryAttempt, deliveryAttemptHeader, handleBatchAndReturnRemaining, handleOne, handleRecord, isAckAfterHandle, 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
-
remainingRecords
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:CommonErrorHandler
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. When true (default), all remaining records including the failed record are passed to the error handler.- Specified by:
remainingRecords
in interfaceCommonErrorHandler
- Returns:
- false to receive only the failed record.
- See Also:
-
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 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:CommonErrorHandler
Called when an exception is thrown with no records available, e.g. if the consumer poll throws an exception.- Specified by:
handleOtherException
in 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:CommonErrorHandler
Handle the exception for a record listener whenCommonErrorHandler.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 interfaceCommonErrorHandler
- 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 completeConsumerRecords
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 interfaceCommonErrorHandler
- Parameters:
thrownException
- the exception.data
- the consumer records.consumer
- the consumer.container
- the container.invokeListener
- a callback to re-invoke the listener.
-