Skip to content
Advertisement

Message not dispatched async despite configuring the handler route to be async in Symfony Messenger

I’m working with Symfony 4.4 and Symfony Messenger

Messenger configuration includes a transport and routing:

messenger:
    failure_transport: failed

    transports:
        async_medium:
            dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
            retry_strategy:
                max_retries: 3
                delay: 1000
        failed:
            ...

    routing:
        'NameSpaceMessageHandlerSnowplowNotificationHandler': async_medium

Though the handler looks like configured correctly (when I run console debug:messenger it shows up correctly assigned to transport)

Messenger

messenger.bus.default

 The following messages can be dispatched:
  NameSpaceMessageSnowplowMessage                                                  
     handled by NameSpaceMessageHandlerSnowplowEmailNotificationHandler  

The message class SnowplowMessage is not queued, but sent instantly to the _invoke() method of the handler.

I’m using AMQP (RabbitMQ as transport) and it’s configured properly as no error is shown and the command console messenger:setup-transport creates the queue properly

Advertisement

Answer

For some reason this seems to be an error that happens with some frequency, so I rather post an answer instead of a comment.

You are supposed to add message classes to the routing configuration, not handler classes.

Your configuration should be, if you want that message to be manages asynchronously:

routing:
        NameSpaceMessageSnowplowMessage: async_medium

What you are routing are message. Since the above configuration was missing, the default routing was processing the message syncrhonously.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement