How to handle messages in batches with Symfony Messenger.

Image by https://www.pexels.com/@renato-k-56319541/

Messenger component

Example dissection

/**
* Flushes any pending buffers.
*
* @param bool $force Whether flushing is required
*/
public function flush(bool $force): void;

Batch Handling

private function shouldFlush(): bool
{
return 15 <= \count($this->jobs);
}
[
[
0: MyMessage,
1: Acknowledger
],
[
0: MyMessage,
1: Acknowledger
],
]

TLDR

Working example

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store