This is how I'm creating an exchange and binding a queue to it
<rabbit:topic-exchange id="dataExchange" name="MQ-EXCHANGE" durable="true">
<rabbit:bindings>
<rabbit:binding queue="COMM_QUEUE" pattern="queue.*" />
</rabbit:bindings>
</rabbit:topic-exchange>
I have read a lot of posts on the Internet where it is written that a message is also needed to be marked persistent if it is to be secured in case rabbitmq or the queue crashes. But I couldn't figure out how to mark my messages persistent.
This is how I'm publishing the messages to the queue
@Autowired
private RabbitTemplate template;
@Override
public void produceMessage(Object message, String routingKey) {
template.convertAndSend(routingKey, message);
}
I looked for different API methods to know this and also tried to look for any specific property that I could configure in the XML but couldn't find a way. Any guidance ?
Persistent messages will be written to disk as soon as they reach the queue, while transient messages will be written to disk only so that they can be evicted from memory while under memory pressure. Persistent messages are also kept in memory when possible and only evicted from memory under memory pressure.
RabbitMQ Durable queues are those that can withstand a RabbitMQ restart. If a queue is not durable, all messages will be lost if RabbitMQ is shut down for any reason. For messages to survive restarts, both of these configurations must be true.
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.
The default delivery mode (in MessageProperties
) is PERSISTENT
. See here.
To make it non-persistent you need to use a convertAndSend(...)
method with a MessagePostProcessor
to set the deliveryMode property.
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