Search code examples
javaspringrabbitmqspring-rabbitdead-letter

How to use RepublishMessageRecoverer in Dead lettering?


I have dead lettering set up for a few queues that I am using. In the configuration I use:

<bean id="retryAdvice"
    class="org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean">
    <property name="messageRecoverer" ref="rejectAndDontRequeueRecoverer"/>
    <property name="retryOperations" ref="retryTemplate" />
</bean>

<bean id="rejectAndDontRequeueRecoverer" class="org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer"/>

If i want the message on the dead letter queue to have the x-exception-stacktrace , I read that I need to use RepublishMessageRecoverer. Is using that in dead lettering as simple as replacing RejectAndDontRequeueRecoverer with RepublishMessageRecoverer in the above setting or do I need to write a custom messageRecoverer?


Solution

  • Yes, just replace the recoverer. Normal RabbitMQ dead lettering is not used at all (the message will be ack'd) and you don't need to configure the DLE/DLQ; you have complete control in the recoverer over where the message goes.