Class ConditionalRejectingErrorHandler
- java.lang.Object
-
- org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler
-
- All Implemented Interfaces:
org.springframework.util.ErrorHandler
public class ConditionalRejectingErrorHandler extends java.lang.Object implements org.springframework.util.ErrorHandlerErrorHandlerthat conditionally wraps the Exception in anAmqpRejectAndDontRequeueExceptionif the configured rejection strategy determines that the message is fatal and should not be requeued. Such messages will be discarded or sent to a Dead Letter Exchange, depending on broker configuration.The default strategy will do this if the exception is a
ListenerExecutionFailedExceptionwith a cause ofMessageConversionException,MessageConversionException,MethodArgumentNotValidException,MethodArgumentTypeMismatchException,NoSuchMethodExceptionorClassCastException.The exception will not be wrapped if the
causechain already contains anAmqpRejectAndDontRequeueException.- Since:
- 1.3.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConditionalRejectingErrorHandler.DefaultExceptionStrategyDefault implementation ofFatalExceptionStrategy.
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Loglogger
-
Constructor Summary
Constructors Constructor Description ConditionalRejectingErrorHandler()Create a handler with theConditionalRejectingErrorHandler.DefaultExceptionStrategy.ConditionalRejectingErrorHandler(FatalExceptionStrategy exceptionStrategy)Create a handler with the suppliedFatalExceptionStrategyimplementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancauseChainContainsARADRE(java.lang.Throwable t)Return true if there is already anAmqpRejectAndDontRequeueExceptionpresent in the cause chain.protected FatalExceptionStrategygetExceptionStrategy()Return the exception strategy.protected voidhandleDiscarded(org.springframework.amqp.core.Message failed)Called when a message with a fatal exception has anx-deathheader, prior to discarding the message.voidhandleError(java.lang.Throwable t)protected booleanisDiscardFatalsWithXDeath()Return the discardFatalsWithXDeath.protected booleanisRejectManual()Return the rejectManual.protected voidlog(java.lang.Throwable t)Log the throwable at WARN level, including stack trace.voidsetDiscardFatalsWithXDeath(boolean discardFatalsWithXDeath)Set to false to disable the (now) default behavior of logging and discarding messages that cause fatal exceptions and have an `x-death` header; which usually means that the message has been republished after previously being sent to a DLQ.voidsetRejectManual(boolean rejectManual)Set to false to NOT reject a fatal message when MANUAL ack mode is being used.
-
-
-
Constructor Detail
-
ConditionalRejectingErrorHandler
public ConditionalRejectingErrorHandler()
Create a handler with theConditionalRejectingErrorHandler.DefaultExceptionStrategy.
-
ConditionalRejectingErrorHandler
public ConditionalRejectingErrorHandler(FatalExceptionStrategy exceptionStrategy)
Create a handler with the suppliedFatalExceptionStrategyimplementation.- Parameters:
exceptionStrategy- The strategy implementation.
-
-
Method Detail
-
isDiscardFatalsWithXDeath
protected boolean isDiscardFatalsWithXDeath()
Return the discardFatalsWithXDeath.- Returns:
- the discardFatalsWithXDeath.
- Since:
- 2.3
- See Also:
setDiscardFatalsWithXDeath(boolean)
-
setDiscardFatalsWithXDeath
public void setDiscardFatalsWithXDeath(boolean discardFatalsWithXDeath)
Set to false to disable the (now) default behavior of logging and discarding messages that cause fatal exceptions and have an `x-death` header; which usually means that the message has been republished after previously being sent to a DLQ.- Parameters:
discardFatalsWithXDeath- false to disable.- Since:
- 2.1
-
isRejectManual
protected boolean isRejectManual()
Return the rejectManual.- Returns:
- the rejectManual.
- Since:
- 2.3
- See Also:
setRejectManual(boolean)
-
setRejectManual
public void setRejectManual(boolean rejectManual)
Set to false to NOT reject a fatal message when MANUAL ack mode is being used.- Parameters:
rejectManual- false to leave the message in an unack'd state.- Since:
- 2.1.9
-
getExceptionStrategy
protected FatalExceptionStrategy getExceptionStrategy()
Return the exception strategy.- Returns:
- the strategy.
- Since:
- 2.3
-
handleError
public void handleError(java.lang.Throwable t)
- Specified by:
handleErrorin interfaceorg.springframework.util.ErrorHandler
-
handleDiscarded
protected void handleDiscarded(org.springframework.amqp.core.Message failed)
Called when a message with a fatal exception has anx-deathheader, prior to discarding the message. Subclasses can override this method to perform some action, such as sending the message to a parking queue.- Parameters:
failed- the failed message.- Since:
- 2.3
-
log
protected void log(java.lang.Throwable t)
Log the throwable at WARN level, including stack trace. Subclasses can override this behavior.- Parameters:
t- theThrowable.- Since:
- 1.7.8
-
causeChainContainsARADRE
protected boolean causeChainContainsARADRE(java.lang.Throwable t)
Return true if there is already anAmqpRejectAndDontRequeueExceptionpresent in the cause chain.- Parameters:
t- aThrowable.- Returns:
- true if the cause chain already contains an
AmqpRejectAndDontRequeueException. - Since:
- 1.7.8
-
-