Class DefaultPulsarConsumerErrorHandler<T>
java.lang.Object
org.springframework.pulsar.listener.DefaultPulsarConsumerErrorHandler<T>
- Type Parameters:
T
- payload type managed by the Pulsar consumer
- All Implemented Interfaces:
PulsarConsumerErrorHandler<T>
public class DefaultPulsarConsumerErrorHandler<T>
extends Object
implements PulsarConsumerErrorHandler<T>
Default implementation for
PulsarConsumerErrorHandler
.
This implementation is capable for handling errors based on the interface contract.
After handling the errors, if necessary, this implementation is capable of recovering
the record(s) using a PulsarMessageRecoverer
Note: This implementation uses a ThreadLocal to manage the current message in error and
it's associated BackOffExecution.
- Author:
- Soby Chacko
-
Constructor Summary
ConstructorDescriptionDefaultPulsarConsumerErrorHandler
(PulsarMessageRecovererFactory<T> pulsarMessageRecovererFactory, BackOff backOff) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the message in error from managing (such as resetting any thread state etc.).org.apache.pulsar.client.api.Message<T>
Returns the current message in error.void
recoverMessage
(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.Message<T> message, Exception exception) Recover the message based on the implementation provided.boolean
shouldRetryMessage
(Exception exception, org.apache.pulsar.client.api.Message<T> message) Decide if the failed message should be retried.
-
Constructor Details
-
DefaultPulsarConsumerErrorHandler
public DefaultPulsarConsumerErrorHandler(PulsarMessageRecovererFactory<T> pulsarMessageRecovererFactory, BackOff backOff)
-
-
Method Details
-
shouldRetryMessage
public boolean shouldRetryMessage(Exception exception, org.apache.pulsar.client.api.Message<T> message) Description copied from interface:PulsarConsumerErrorHandler
Decide if the failed message should be retried.- Specified by:
shouldRetryMessage
in interfacePulsarConsumerErrorHandler<T>
- Parameters:
exception
- throws exceptionmessage
- Pulsar message- Returns:
- if the failed message should be retried or not
-
recoverMessage
public void recoverMessage(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.Message<T> message, Exception exception) Description copied from interface:PulsarConsumerErrorHandler
Recover the message based on the implementation provided. Once this method returns, callers can assume that the message is recovered and has not been acknowledged yet.- Specified by:
recoverMessage
in interfacePulsarConsumerErrorHandler<T>
- Parameters:
consumer
- Pulsar consumermessage
- Pulsar messageexception
- thrown exception
-
currentMessage
Description copied from interface:PulsarConsumerErrorHandler
Returns the current message in error.- Specified by:
currentMessage
in interfacePulsarConsumerErrorHandler<T>
- Returns:
- the Pulsar Message currently tracked by the error handler
-
clearMessage
public void clearMessage()Description copied from interface:PulsarConsumerErrorHandler
Clear the message in error from managing (such as resetting any thread state etc.).- Specified by:
clearMessage
in interfacePulsarConsumerErrorHandler<T>
-