I am using an external service (Service) to process some particular type of objects. The Service works faster if I send objects in batches of 10. My current architecture is as follows. A producer broadcasts objects one-by-one, and a bunch of consumers pull them (one-by-one) from a queue and send them to The Service. This is obviously suboptimal.
I don't want to modify producer code as it can be used in different cases. I can modify consumer code but only with the cost of additional complexity. I'm also aware of the prefetch_count
option but I think it only works on the network level -- the client library (pika) does not allow fetching multiple messages at once in the consumer callback.
So, can RabbitMQ create batches of messages before sending them to consumers? I'm looking for an option like "consume n messages at a time".
prefetch_count
? You can consumeN
number of messages, count them, and once your count exceed some value, process them all in once. In addition you can accnowledge them in batch. – Campanilen < N
items in the queue? Then the consumer will hang for an indeterminate amount of time waiting forN - n
more messages to be queued. In my case, this is a crucial problem. – Meteor