phpsymfonysymfony-messenger

Can symfony messenger handle messages in "bulk"


I was wondering, because I can not find anything on symfony or other resources, if php's symfony/messenger can handle messages in "bulk" with any async transport.

For example. Grab 20 messages from the bus, handle those 20 messages, and ack or reject any of the messages.

I know RabbitMQ has a feature to grab n-amount of messages from the queue, and process all of them in a single run. In some cases this will have a better performance over scaling the async workers.

Does anybody have any leads, resources or experience with it? Or am I trying to resolve something by going against the idea of symfony/messenger?

[update]

I'm aware that bulk messages are not part of the (async) messaging concept. That each message should be processed individually. But some message brokers have implemented a feature to "grab" X-amount of messages from a queue and process them (either by sending an acknowledge or rejection, or otherwise). I know handling multiple messages in a single iteration increases complexity of any consumers, but in some cases it will improve performance.

I've used this concept of consuming multiple messages in a single iteration many times, but never with php's symfony/messenger.


Solution

  • This was not natively possible prior to symfony 5.4.

    They added a BatchHandlerInterface which will allow you to batch (and choose the size of the batch) your messages.

    You can find more info here :