2

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.

denis
  • 1,393
  • 3
  • 14
  • 34
  • The problem is likely that your transport referenced under `failure_transport` does not exist. Just copy the `transport: async` as `failed` and possible add a queue name `failed: '%env(MESSENGER_TRANSPORT_DSN)%?queue_name=failed'` – dbrumann Jul 25 '19 at 13:10
  • @dbrumann I'm sorry this was a copy and paste error of the messenger config. I have corrected it in the question. It still doesn't work. (same exception) – denis Jul 25 '19 at 13:19
  • Could it be that you accidentally misconfiguried the Message Bus in your service configuration? Could you run `bin/console debug:container 'Symfony\Component\Messenger\MessageBusInterface'` and check that it is in fact a service based on MessageBus? – dbrumann Jul 25 '19 at 13:23
  • Hmm to be honest I've just done the steps in the documentation. Here is what I'm getting with the debug command: https://gist.github.com/DenisMir/53a166187768fa252665be07891a68c1 When I'm interpreting it correctly I think that the bus is configured correctly. If that wasn't the case I would expect the dispatch to fail as well. – denis Jul 25 '19 at 13:30
  • 1
    Yes, that looks correct. I have not encountered this before, but I am rarely using the Doctrine transport. Maybe I have time tomorrow to see if I can reproduce this issue, if no one else finds a solution until then – dbrumann Jul 25 '19 at 13:46

1 Answers1

2

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.

denis
  • 1,393
  • 3
  • 14
  • 34