Class CommonLoggingErrorHandler
java.lang.Object
org.springframework.kafka.listener.CommonLoggingErrorHandler
- All Implemented Interfaces:
CommonErrorHandler,DeliveryAttemptAware
The
CommonErrorHandler implementation for logging exceptions.- Since:
- 2.8
- Author:
- Gary Russell
-
Constructor Summary
Constructors -
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.booleanhandleOne(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 whenCommonErrorHandler.seeksAfterHandling()returns false.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.booleanReturn true if the offset should be committed for a handled error (no exception thrown).voidsetAckAfterHandle(boolean ackAfterHandle) 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, waitMethods inherited from interface org.springframework.kafka.listener.CommonErrorHandler
clearThreadState, deliveryAttempt, deliveryAttemptHeader, handleBatchAndReturnRemaining, handleRemaining, logger, onPartitionsAssigned, seeksAfterHandling
-
Constructor Details
-
CommonLoggingErrorHandler
public CommonLoggingErrorHandler()
-
-
Method Details
-
isAckAfterHandle
public boolean isAckAfterHandle()Description copied from interface:CommonErrorHandlerReturn true if the offset should be committed for a handled error (no exception thrown).- Specified by:
isAckAfterHandlein interfaceCommonErrorHandler- Returns:
- true to commit.
-
setAckAfterHandle
public void setAckAfterHandle(boolean ackAfterHandle) Description copied from interface:CommonErrorHandlerSet 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:
setAckAfterHandlein interfaceCommonErrorHandler- Parameters:
ackAfterHandle- false to not commit.
-
handleOne
public boolean handleOne(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container) Description copied from interface:CommonErrorHandlerHandle the exception for a record listener whenCommonErrorHandler.seeksAfterHandling()returns false. Use this to handle just the single failed record.- Specified by:
handleOnein interfaceCommonErrorHandler- 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:
-
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.
-
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.
-