4

I'm trying to use Symfony Messenger in a project which does not use whole Symfony Framework.

I achieved creating a message, routing it to my handler and getting the result back with following code:

<?php

require 'vendor/autoload.php';

class MyMessage
{
    public $message;
}

class MyMessageHandler implements \Symfony\Component\Messenger\Handler\MessageHandlerInterface
{
    public function __invoke(MyMessage $message)
    {
        return [
            'success' => true,
            'message' => $message,
        ];
    }
}

$myMessageHandler = new MyMessageHandler();

$bus = new \Symfony\Component\Messenger\MessageBus([
    new \Symfony\Component\Messenger\Middleware\HandleMessageMiddleware(
        new \Symfony\Component\Messenger\Handler\HandlersLocator([
            MyMessage::class => [$myMessageHandler]
        ])
    )
]);

$message1 = new MyMessage();
$message1->message = 'Sample message';
$envelope = $bus->dispatch($message1);
$stamp = $envelope->last(\Symfony\Component\Messenger\Stamp\HandledStamp::class);
$result = $stamp->getResult();
dump($result);

But i can't find the way to add AMQP Transport to this config for sending my commands to RabbitMQ.

How can i do this? Thanks.

cnkt
  • 2,943
  • 5
  • 30
  • 43
  • you probably need to install https://github.com/symfony/amqp-messenger assuming you may have overlooked that section in https://symfony.com/doc/current/messenger.html#amqp-transport I don't know how to integrate it in a minimalistic setup like yours. – Jakumi Jul 27 '20 at 11:38
  • @Jakumi i required it in composer but i don't know how to integrate it in this config. – cnkt Jul 27 '20 at 12:26
  • I cannot give you an exact path, but my guess is that you need to instance `AmqpTransportFactory` to create the connection, and `SendMessageMiddleware` with its `SendersLocator`. – msg Oct 23 '20 at 00:01

0 Answers0