Jatin S Bhavra
Jatin S Bhavra

Reputation: 65

How we can use the BatchingRabbitTemplate to read the messages as a batch from the RabbitMQ queue?

I am trying the scenario where I need to read a batch of messages from the queue e,g,. There are 100 messages in the queue and I want to take 10 messages from the queue in a single call.

the BatchingRabbitTemplate provides the functionality of sending messages into RabbitMQ as a batch. Can we use same for reading the messages from the queue as a batch without using BatchingRabbitTemplate for publishing the messages?

Upvotes: 1

Views: 1936

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

The Listener Container automatically "de-batchs" those message. See Reference Manual.

If you need just receive them as single batch message, you should switch off the option on the container via:

/**
 * Determine whether or not the container should de-batch batched
 * messages (true) or call the listener with the batch (false). Default: true.
 * @param deBatchingEnabled the deBatchingEnabled to set.
 */
public void setDeBatchingEnabled(boolean deBatchingEnabled)

But, eh, you can use standard RabbitTemplate.receive() and and that will return single batch message for you.

To de-batch and receive message one by one you should go to the Listener Container anyway.

Upvotes: 2

Related Questions