Class ConditionalDelegatingBatchErrorHandler
- java.lang.Object
-
- org.springframework.kafka.listener.ConditionalDelegatingBatchErrorHandler
-
- All Implemented Interfaces:
BatchErrorHandler
,ConsumerAwareBatchErrorHandler
,ContainerAwareBatchErrorHandler
,GenericErrorHandler<org.apache.kafka.clients.consumer.ConsumerRecords<?,?>>
public class ConditionalDelegatingBatchErrorHandler extends java.lang.Object implements ContainerAwareBatchErrorHandler
An error handler that delegates to different error handlers, depending on the exception type.- Since:
- 2.7.4
- Author:
- Gary Russell
-
-
Constructor Summary
Constructors Constructor Description ConditionalDelegatingBatchErrorHandler(ContainerAwareBatchErrorHandler defaultErrorHandler)
Construct an instance with a default error handler that will be invoked if the exception has no matches.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDelegate(java.lang.Class<? extends java.lang.Throwable> throwable, ContainerAwareBatchErrorHandler handler)
Add a delegate to the end of the current collection.protected void
doHandle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)
void
handle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)
Handle the exception.void
handle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)
Handle the exception.void
setErrorHandlers(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,ContainerAwareBatchErrorHandler> delegates)
Set the delegate error handlers; aLinkedHashMap
argument is recommended so that the delegates are searched in a known order.-
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.ConsumerAwareBatchErrorHandler
handle
-
Methods inherited from interface org.springframework.kafka.listener.ContainerAwareBatchErrorHandler
handle
-
Methods inherited from interface org.springframework.kafka.listener.GenericErrorHandler
clearThreadState, isAckAfterHandle, setAckAfterHandle
-
-
-
-
Constructor Detail
-
ConditionalDelegatingBatchErrorHandler
public ConditionalDelegatingBatchErrorHandler(ContainerAwareBatchErrorHandler defaultErrorHandler)
Construct an instance with a default error handler that will be invoked if the exception has no matches.- Parameters:
defaultErrorHandler
- the default error handler.
-
-
Method Detail
-
setErrorHandlers
public void setErrorHandlers(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,ContainerAwareBatchErrorHandler> delegates)
Set the delegate error handlers; aLinkedHashMap
argument is recommended so that the delegates are searched in a known order.- Parameters:
delegates
- the delegates.
-
addDelegate
public void addDelegate(java.lang.Class<? extends java.lang.Throwable> throwable, ContainerAwareBatchErrorHandler handler)
Add a delegate to the end of the current collection.- Parameters:
throwable
- the throwable for this handler.handler
- the handler.
-
handle
public void handle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)
Description copied from interface:BatchErrorHandler
Handle the exception.- Specified by:
handle
in interfaceBatchErrorHandler
- Specified by:
handle
in interfaceConsumerAwareBatchErrorHandler
- Specified by:
handle
in interfaceContainerAwareBatchErrorHandler
- Parameters:
thrownException
- the exception.records
- the consumer records.consumer
- the consumer.container
- the container.
-
handle
public void handle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)
Description copied from interface:ContainerAwareBatchErrorHandler
Handle the exception.- Specified by:
handle
in interfaceBatchErrorHandler
- Specified by:
handle
in interfaceContainerAwareBatchErrorHandler
- Parameters:
thrownException
- the exception.records
- the consumer records.consumer
- the consumer.container
- the container.invokeListener
- a callback to re-invoke the listener.
-
doHandle
protected void doHandle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, @Nullable java.lang.Runnable invokeListener)
-
-