Description
Symfony version(s) affected
6.2.9
Description
Due to documentation https://symfony.com/doc/current/messenger.html#routing-messages-to-a-transport we can define a default routing for all messages.
You may use '*' as the message class. This will act as a default routing rule for any message not matched under routing. This is useful to ensure no message is handled synchronously by default.
$messenger
->routing('*')
->senders(['async']);
When we want to set a specific sender for a specific message we should use the code
$messenger->routing(MyMessage::class)->sender(['another_async']);
In my opinion this should rewrite the transport for this one specific message and send the message only to 'another_async' transport.
In reality the message is sent to async + to another_async transports. So the default '*' acts like a template for message namespaces
You may use a partial PHP namespace like 'App\Message*' to match all the messages within the matching namespace. The only requirement is that the '*' wildcard has to be placed at the end of the namespace.
How to reproduce
return static function (FrameworkConfig $framework) {
$messenger = $framework->messenger();
$messenger
->transport('async')
->dsn('doctrine://default')
->retryStrategy(['max_retries' => 3, 'multiplier' => 1, 'delay' => 1000]);
$messenger
->transport('another_async')
->dsn('doctrine://default')
->retryStrategy(['max_retries' => 4, 'multiplier' => 2, 'delay' => 1000]);
$messenger
->routing('*')
->senders(['async']);
$messenger->routing(MyMessage::class)->sender(['another_async']);
}
Possible Solution
I see 2 possible solutions
- Change the documentation and specify that setting a routing for the specific message adds, not replaces, the routing.
- Change the behavior of routing()->senders([]) which will replace the senders for the specific message
Additional Context
No response