Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Symfony\Messenger] Default routing duplicates messages #51024

Copy link
Copy link
Closed as not planned
@jokaorgua

Description

@jokaorgua
Issue body actions

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

  1. Change the documentation and specify that setting a routing for the specific message adds, not replaces, the routing.
  2. Change the behavior of routing()->senders([]) which will replace the senders for the specific message

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.