3

I'm trying to use Symfony Messenger in my project without Symfony Framework.

class MessengerCommandBus implements CommandBusInterface
{
    /**
     * @var MessageBusInterface
     */
    private MessageBusInterface $commandBus;

    public function __construct(MessageBusInterface $commandBus)
    {

        $this->commandBus = $commandBus;
    }

    public function dispatch(CommandInterface $command): void
    {
        $this->commandBus->dispatch($command);
    }
}

And I want to use it in my Controller (php8)

final class DirectionController
{
    public function __construct(
        private CommandBusInterface $commandBus
        private QueryBusInterface $queryBus
    ) {}
    public function createDirection() {
        $this->commandBus->dispatch(new CreateDirectionCommand('Symfony'));
    }
}

I put the controller and bus into services.yml

direction.web.controller:
    class: 'Company\Infrastructure\Web\DirectionController'
    autowire: true
    public: true

Company\Application\CQRS\Command\CommandBusInterface $commandBus: '@Company\Infrastructure\Bus\MessengerCommandBus'

But of course, I need to create MessageBusInterface implementation in MessengerCommandBus. With Symfony framework, I can create it with messenger.yml but I use the component standalone and I don't have it. Where I can configure the bus in this case? Should I create a new MessengerBus with $commandBus = new MessageBus([]),$queryBus = new MessageBus([]) but it doesn't implement MessageBusInterface or should I configure it in another place? I can't understand the docs about Messenger ((

Slip
  • 939
  • 6
  • 17
  • 40
  • 2
    Same issue here, the documentation is a PITA if you don't use the framework... So much about SF being made of decoupled components... It would be awesome if the documentation would also contain a frameworkless guide! – floriank Feb 22 '22 at 23:51

0 Answers0