0

I am looking to use Mercury with RabbitMQ. This is the first time that I have used Mercury as well as RabbitMQ so I am not yet good.

Here is where I am:

I've installed Mercure, and Messenger.

Messenger.yaml

framework:
    messenger:
        # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
        failure_transport: failed

        transports:
            # https://symfony.com/doc/current/messenger.html#transport-configuration
             async: '%env(MESSENGER_TRANSPORT_DSN)%'
             failed: '%env(MESSENGER_TRANSPORT_FAILED_DSN)%'
            # sync: 'sync://'

        routing:
            # Route your messages to the transports
            # 'App\Message\YourMessage': async

.env:

MERCURE_PUBLISH_URL=http://localhost:3000/.well-known/mercure
MERCURE_JWT_TOKEN=aVerySecretKey
MESSENGER_TRANSPORT_DSN=amqp://bastien:mypassword@localhost:5672/%2f/messages
MESSENGER_TRANSPORT_FAILED_DSN=amqp://bastien:mypassword@localhost:5672/%2f/failed

And in my controller I simulated 50 pings on a URL of my local app:

    /**
     * @Route("/ping", name="ping", methods={"POST"})
     */
    public function ping(MessageBusInterface $bus)
    {
        for($i=0;$i<=50;$i++)
        {
            $update = new Update("http://monsite.com/ping", "[]");
            $bus->dispatch($update);
        }
        return $this->redirectToRoute('home');
    }

I have successfully started my instance of Mercury as well as that of Messenger which is therefore well connected to my RabbitMQ.

But when I test sending the pings, it works, but without going through my RabbitMQ. Did I miss something? I think of my Messenger.yaml in the routing part but I don't know what to put if it is the case

eronn
  • 1,690
  • 3
  • 21
  • 53
  • 1
    By default, messages are executed synchronously in messenger. You may need to configure the Update message in the messenger.yaml to use the async transport – G1.3 Dec 02 '20 at 14:56
  • Oooooh okay ! I just added `Symfony\Component\Mercure\Update: async` for the routing in the `messenger.yaml`, and now it works very good ! I understand better how it works now ! Thank you very much ! – eronn Dec 02 '20 at 15:12

1 Answers1

1

By default, messages are executed synchronously in messenger.

You will need to configure the Update message in the messenger.yaml to use the async transport:

Symfony\Component\Mercure\Update: async
G1.3
  • 1,693
  • 8
  • 24
  • Yes it works very well! On the other hand, if I have an application coded in Python and where I need to put in my RabbitMQ elements which should be intercepted by my Symfony application with Messenger, is this possible? Because on my Python application I will not be able to use Messenger or put an "Update" object in the RabbitMQ waiting list. – eronn Dec 03 '20 at 09:37
  • You can have a look at the message Symfony is sending when dispatching the Update message. If not easy/clean to work with, you can add an intermediate step: pushing from Python to a queue, consuming and in that consumer dispatching a well formed Update message with the envelope. This can help: https://symfonycasts.com/screencast/messenger/external-transport – G1.3 Dec 03 '20 at 09:51