handleMessage method does not get the message from queue if I add MessageProperties in its signature. It works fine if there is no MessageProperties.
How can I get MessageProperties in handleMessage of MessageListenerAdapter?
public class EventMessageAdapter {
public void handleMessage(MessageProperties messageProperties, Event event) {
...
String id = messageProperties.getHeaders().get("key");
}
org.springframework.amqp » spring-amqpApache. Supports for AMQP-based messaging applications. It provides high-level abstractions for sending and receiving messages. Last Release on Sep 19, 2022.
Annotation that marks a method to be the target of a Rabbit message listener on the specified queues() (or bindings() ). The containerFactory() identifies the RabbitListenerContainerFactory to use to build the rabbit listener container.
Helper class that simplifies synchronous RabbitMQ access (sending and receiving messages). The default settings are for non-transactional messaging, which reduces the amount of data exchanged with the broker. To use a new transaction for every send or receive set the channelTransacted flag.
public RabbitAdmin(RabbitTemplate rabbitTemplate) Construct an instance using the provided RabbitTemplate . Use this constructor when, for example, you want the admin operations to be performed within the scope of the provided template's invoke() method.
You can't do it with the listener adapter.
Use the newer-style @RabbitListener
mechanism docs here.
You can use various signatures...
@RabbitListener(queues = "foo")
public void foo(Event event, @Header("foo") String fooHeader,
@Header("bar") Integer barHeader) {...}
or
@RabbitListener(queues = "bar")
public void bar(Event event, Message message) {...}
In the second case you can get all the message properties via
message.getMessageProperties()
.
You need a container factory. Spring Boot creates one automatically for you if the starter is on the classpath.
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