Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the earliest point of entry to read a rabbit message in spring-amqp?

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.

like image 888
kinbiko Avatar asked Jan 18 '18 09:01

kinbiko


People also ask

What is the default value of spring RabbitMQ address?

However in this guide, the RabbitMQ configuration is as default(localhost server and with credential as guest/guest).

What is spring boot starter AMQP?

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".

What is SpringFramework AMQP?

Group: SpringFramework AMQP It provides high-level abstractions for sending and receiving messages. Last Release on Sep 19, 2022.


1 Answers

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.

like image 133
Artem Bilan Avatar answered Sep 22 '22 11:09

Artem Bilan