I store thread-local rabbit message data in an MDC. I would like to clear the old and add new context data for an incoming rabbit message, like reading certain values from the headers or reading the rabbit message payload as a byte[]
. Unfortunately I often see exceptions happening prior to the message hitting my @RabbitHandler
annotated methods. Is there an earlier entry-point that I can hook into to establish this context? I don't know what happens before deserialization occurs, but ideally I'd like access to the message before attempting to deserialize it. Perhaps there's an onMessageReceived(byte[] message, Map headers)
method hook somewhere. The earlier in the call stack the better.
However in this guide, the RabbitMQ configuration is as default(localhost server and with credential as guest/guest).
The Spring AMQP project applies core Spring concepts to the development of AMQP-based messaging solutions. It provides a "template" as a high-level abstraction for sending and receiving messages. It also provides support for Message-driven POJOs with a "listener container".
Group: SpringFramework AMQP It provides high-level abstractions for sending and receiving messages. Last Release on Sep 19, 2022.
The @RabbitHandler
is populated by the AbstractRabbitListenerContainerFactory
which can be supplied with the custom MessageConverter
: https://docs.spring.io/spring-amqp/docs/2.0.1.RELEASE/reference/html/_reference.html#message-converters. Its fromMessage()
is called from the MessagingMessageListenerAdapter.toMessagingMessage()
. And that is done in the MessagingMessageListenerAdapter.onMessage()
. That's indeed very early place you can hook. And you really there still have a raw org.springframework.amqp.core.Message
object without any conversion and with all available headers and properties.
Well, you also can inject:
/**
* @param afterReceivePostProcessors the post processors.
* @see AbstractMessageListenerContainer#setAfterReceivePostProcessors(MessagePostProcessor...)
*/
public void setAfterReceivePostProcessors(MessagePostProcessor... afterReceivePostProcessors) {
With similar reason you are requesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With