Skip to content

Navigation Menu

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

[Messenger] Redispatch a message in the same transport as the one defined in the configuration #60132

Copy link
Copy link
Open
@lyrixx

Description

@lyrixx
Issue body actions

Description

see last chapter of: https://symfony.com/doc/current/scheduler.html#efficient-management-with-symfony-scheduler

By default the scheduler process the message synchronously:

RecurringMessage::every('1 second', new CheckTrafficAnomalies()),

scheduler logs:

08:13:36 INFO      [messenger] Received message AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies"]
CALLLLLLLLLLLLLLLLLLLLED
08:13:36 INFO      [messenger] Message AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies handled by AppBundle\NotificationCenter\Messenger\MessageHandler\CheckTrafficAnomaliesHandler::__invoke ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies","handler" => "AppBundle\NotificationCenter\Messenger\MessageHandler\CheckTrafficAnomaliesHandler::__invoke"]
08:13:36 INFO      [messenger] AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies was handled successfully (acknowledging to transport). ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies","message_id" => null]

We can tell it to dispatch the message to the bus, it's still synchronous

RecurringMessage::every('1 second', new RedispatchMessage(new CheckTrafficAnomalies())),

scheduler logs:

08:14:06 INFO      [messenger] Received message Symfony\Component\Messenger\Message\RedispatchMessage ["class" => "Symfony\Component\Messenger\Message\RedispatchMessage"]
CALLLLLLLLLLLLLLLLLLLLED
08:14:06 INFO      [messenger] Message AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies handled by AppBundle\NotificationCenter\Messenger\MessageHandler\CheckTrafficAnomaliesHandler::__invoke ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies","handler" => "AppBundle\NotificationCenter\Messenger\MessageHandler\CheckTrafficAnomaliesHandler::__invoke"]
08:14:06 INFO      [messenger] Message Symfony\Component\Messenger\Message\RedispatchMessage handled by Symfony\Component\Messenger\Handler\RedispatchMessageHandler::__invoke ["class" => "Symfony\Component\Messenger\Message\RedispatchMessage","handler" => "Symfony\Component\Messenger\Handler\RedispatchMessageHandler::__invoke"]
08:14:06 INFO      [messenger] Symfony\Component\Messenger\Message\RedispatchMessage was handled successfully (acknowledging to transport). ["class" => "Symfony\Component\Messenger\Message\RedispatchMessage","message_id" => null]

An finally we can specify a transport:

scheduler logs:

08:15:23 INFO      [messenger] Received message Symfony\Component\Messenger\Message\RedispatchMessage ["class" => "Symfony\Component\Messenger\Message\RedispatchMessage"]
08:15:23 INFO      [messenger] Sending message AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies with rabbitmq sender using Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpTransport ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies","alias" => "rabbitmq","sender" => "Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpTransport"]
08:15:23 INFO      [messenger] Message Symfony\Component\Messenger\Message\RedispatchMessage handled by Symfony\Component\Messenger\Handler\RedispatchMessageHandler::__invoke ["class" => "Symfony\Component\Messenger\Message\RedispatchMessage","handler" => "Symfony\Component\Messenger\Handler\RedispatchMessageHandler::__invoke"]
08:15:23 INFO      [messenger] Symfony\Component\Messenger\Message\RedispatchMessage was handled successfully (acknowledging to transport). ["class" => "Symfony\Component\Messenger\Message\RedispatchMessage","message_id" => null]

In another worker (bin/console mes:con rabbitmq)

08:15:08 INFO      [messenger] Received message AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies"]
CALLLLLLLLLLLLLLLLLLLLED
08:15:08 INFO      [messenger] Message AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies handled by AppBundle\NotificationCenter\Messenger\MessageHandler\CheckTrafficAnomaliesHandler::__invoke ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies","handler" => "AppBundle\NotificationCenter\Messenger\MessageHandler\CheckTrafficAnomaliesHandler::__invoke"]
08:15:08 INFO      [messenger] AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies was handled successfully (acknowledging to transport). ["class" => "AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies","message_id" => null]


There is something I don't like here. I must duplicate the configuration between messenger.yaml (routing), and the second argument rabbitmq of new RedispatchMessage().

framework:
    messenger:
        routing:
            'AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies': rabbitmq

I noticed that few years ago, but was too lazy to raise the issue.

But now I face a real problem with that.

Depending on where I deploy the application, I want to use another transport for this message.
So I added another "config_override.yaml" (highest priority) file in my app :

framework:
    messenger:
        routing:
            'AppBundle\NotificationCenter\Messenger\Message\CheckTrafficAnomalies': in_memory

But it doesn't work since the transport is hardcoded is hardcoded.


So I propose the following

  1. If the transport name is not defined by the user (null) we use the transport configured in the configuration
  2. If it's not possible because of BC, we can use a special parameter like true to use the default

WDYT?

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.