symfonysymfony4symfony-messenger

Symfony Messenger 4.3 - Consuming messages from doctrine transport fails (exception thrown)


Symfony version: 4.3.2

PHP: 7.2.20

I am trying to use the messenger component with the doctrine transport asynchronously. I have installed the messenger via composer require messenger with the help of Symfony Flex.

I have activated the doctrine transport by MESSENGER_TRANSPORT_DSN=doctrine://default in the .env.local. In the messenger config the transport is configured as well:

framework:
    messenger:   
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            'App\Message\SomeNotification': async

When dispatching the message in the controller with $this->dispatchMessage(new SomeNotification('some content')); everything is fine. The table messenger_messages of the doctrine transport gets created automatically and the message is saved in the table correctly.

When trying to consume the message with ./bin/console messenger:consume async I'm getting the following error:

 [Symfony\Component\Debug\Exception\FatalThrowableError]                                                                                                                                                                                                               
  Argument 2 passed to Symfony\Component\Messenger\Worker::__construct() must implement interface Symfony\Component\Messenger\MessageBusInterface, string given, called in ..../vendor/symfony/messenger/  
  Command/ConsumeMessagesCommand.php on line 190       

So the $routableBus in the Symfony\Component\Messenger\Command\ConsumeMessagesCommand is empty which leads to the crash when instantiating the Worker.


Solution

  • The answer for the question is to update symfony/framework-bundle to 4.3.2 as well. Due to a bug in the composer.json of the messenger component version 4.3.2 of the framework bundle is not enforced. This leads to the default misconfiguration when using an older version of the symfony/framework-bundle in combination with 4.3.2 of the messenger component. This explained my error since I had 4.3.0 of the framework bundle installed.

    More about it can be found on the GitHub issue tracker right here:

    https://github.com/symfony/symfony/issues/32738

    After updating the symfony/framework-bundle everything works as expected.