Reputation:
I search accross google answer to my question, but I didn't manage to find an clear answer. Is it possible to batch sended messages in rabbitmq ?
Upvotes: 3
Views: 17036
Reputation: 215
AFAIK and in accordance with official documentation (most tightly related to your question topic, with examples in Java https://www.rabbitmq.com/tutorials/tutorial-seven-java.html) there is such a thing called "batching publisher confirms".
I mean you basically cannot publish multiple messages at one time (I also dig into an API of Java and even in the most recent versions, such as 5.12.0, and there is completely no such API that provides publishing multiple messages at one batch). Even in documentation as an example of publishing multiple messages they basically use something like this :
int batchSize = 100;
int outstandingMessageCount = 0;
while (thereAreMessagesToPublish()) {
byte[] body = ...;
BasicProperties properties = ...;
channel.basicPublish(exchange, queue, properties, body);
outstandingMessageCount++;
if (outstandingMessageCount == batchSize) {
ch.waitForConfirmsOrDie(5_000);
outstandingMessageCount = 0;
}
}
if (outstandingMessageCount > 0) {
ch.waitForConfirmsOrDie(5_000);
}
And I wager it is defiantly not what you want, because here they basically publish 100 messages separately, but confirms them as one batch. That is what I mean when said "batching publisher confirms" - simply confirm that multiple messages have reached broker successfully, but messages themselves are published separately, one by one.
I really hope this answer help someone. Completely appreciate any addition.
Upvotes: 4
Reputation: 15785
This has been discussed before, and RabbitMQ is not supporting batch publish now. You have to bundle them up in one message by yourself.
Please see: http://rabbitmq.1065348.n5.nabble.com/Batching-messages-td22852.html
Upvotes: 2