Class CommonLoggingErrorHandler
- java.lang.Object
-
- org.springframework.kafka.listener.CommonLoggingErrorHandler
-
- All Implemented Interfaces:
CommonErrorHandler
,DeliveryAttemptAware
public class CommonLoggingErrorHandler extends java.lang.Object implements CommonErrorHandler
TheCommonErrorHandler
implementation for logging exceptions.- Since:
- 2.8
-
-
Constructor Summary
Constructors Constructor Description CommonLoggingErrorHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.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
handleRecord(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)
Deprecated.boolean
isAckAfterHandle()
Return true if the offset should be committed for a handled error (no exception thrown).void
setAckAfterHandle(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, wait
-
Methods inherited from interface org.springframework.kafka.listener.CommonErrorHandler
clearThreadState, deliveryAttempt, deliveryAttemptHeader, handleBatchAndReturnRemaining, handleOne, handleRemaining, onPartitionsAssigned, onPartitionsAssigned, remainingRecords, seeksAfterHandling
-
-
-
-
Method Detail
-
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 interfaceCommonErrorHandler
- Returns:
- true to commit.
-
setAckAfterHandle
public void setAckAfterHandle(boolean ackAfterHandle)
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 interfaceCommonErrorHandler
- Parameters:
ackAfterHandle
- false to not commit.
-
handleRecord
@Deprecated public void handleRecord(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)
Deprecated.Description copied from interface:CommonErrorHandler
Handle the exception for a record listener whenCommonErrorHandler.remainingRecords()
returns false. Use this to handle just the single failed record; remaining records from the poll will be sent to the listener.- Specified by:
handleRecord
in interfaceCommonErrorHandler
- Parameters:
thrownException
- the exception.record
- the record.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 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.
-
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 interfaceCommonErrorHandler
- Parameters:
thrownException
- the exception.consumer
- the consumer.container
- the container.batchListener
- true if the listener is a batch listener.
-
-