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
ConstructorsConstructorDescriptionDefaultPulsarConsumerErrorHandler(PulsarMessageRecovererFactory<T> pulsarMessageRecovererFactory, BackOff backOff) -
Method Summary
Modifier and TypeMethodDescriptionvoidClear 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.voidrecoverMessage(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.booleanshouldRetryMessage(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:PulsarConsumerErrorHandlerDecide if the failed message should be retried.- Specified by:
shouldRetryMessagein 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:PulsarConsumerErrorHandlerRecover 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:
recoverMessagein interfacePulsarConsumerErrorHandler<T>- Parameters:
consumer- Pulsar consumermessage- Pulsar messageexception- thrown exception
-
currentMessage
Description copied from interface:PulsarConsumerErrorHandlerReturns the current message in error.- Specified by:
currentMessagein interfacePulsarConsumerErrorHandler<T>- Returns:
- the Pulsar Message currently tracked by the error handler
-
clearMessage
public void clearMessage()Description copied from interface:PulsarConsumerErrorHandlerClear the message in error from managing (such as resetting any thread state etc.).- Specified by:
clearMessagein interfacePulsarConsumerErrorHandler<T>
-