Symfony Messenger component keeps evolving to meet the needs of complex, modern applications. In Symfony 7.3, we're introducing several powerful features to it.

Run Process Using the Shell

Kevin Macquer
Contributed by Kevin Macquer in #59768

The RunProcessMessage allows you to run a command via the Process component by dispatching a message. In Symfony 7.3, we're improving it with a new fromShellCommandline() method that lets you use shell features such as redirections or pipes:

1
2
3
4
5
6
7
use Symfony\Component\Process\Messenger\RunProcessMessage;

$this->bus->dispatch(
    RunProcessMessage::fromShellCommandline(
        'php bin/console app:export-orders | gzip > var/exports/orders.csv.gz'
    )
);

Doctrine Keepalive Support

Silas Joisten
Contributed by Silas Joisten in #59601

Symfony Messenger already supports the keepalive feature for Beanstalkd, Amazon SQS, and Redis transports. In Symfony 7.3, we're adding keepalive support for the Doctrine transport as well.

Use the new --keepalive option to periodically update the delivered_at timestamp and prevent redelivery of long-running messages:

1
$ php bin/console messenger:consume --keepalive

Allow to Close Transport Connection

Andrii Dembitskyi
Contributed by Andrii Dembitskyi in #59862

Long-running processes can stress the application by leaking memory or consuming growing amounts of system resources. In Symfony 7.3, you can now manually close a transport connection to free its resources.

This is done via the new close() method from Symfony\Component\Messenger\Transport\CloseableTransportInterface, implemented by Amazon SQS, AMQP, and Redis transports.

To close Doctrine connections, use the Doctrine middleware as documented.

Filtering Messages to Remove

Arnaud De Abreu
Contributed by Arnaud De Abreu in #59978

The messenger:failed:show command includes a --class-filter option to filter which type of failed messages to display. Symfony 7.3 adds the same option to the messenger:failed:remove command:

1
2
3
$ bin/console messenger:failed:remove --class-filter="App\Message\MyMessage"

 There are 16 messages to remove. Do you want to continue? (yes/no) [yes]:

Deduplication Middleware

Vincent Langlet
Contributed by Vincent Langlet in #54141

When adding new messages to a queue, you might accidentally enqueue duplicates. These can waste resources and trigger unintended side effects.

Symfony 7.3 introduces a deduplication middleware that automatically filters out identical messages based on their body content. If a message with the same content is already in the queue, the new one is skipped.

To use it, your application must have the Lock component installed and use a lock store that supports serialization. Once that's in place, the middleware is enabled automatically. You just need to add a stamp to the messages you want to deduplicate:

1
2
3
4
5
use Symfony\Component\Messenger\Stamp\DeduplicateStamp;

$bus->dispatch(new MyMessage('...'), [
    new DeduplicateStamp('the-lock-resource'),
]);
Published in #Living on the edge