sroze / messenger-enqueue-transport

Uses Enqueue with Symfony's Messenger component.
MIT License
191 stars 54 forks source link

Use AMQP topic exchange #56

Open PxlCtzn opened 5 years ago

PxlCtzn commented 5 years ago

Hi,

For several days i've been trying to figure how to configure enqueue to work with the an AMQP Topic exchange. According to the given documentation, here is the messenger.yml config file:

framework:
    messenger:
        transports:
            amqp_book_search: enqueue://default
                ?queue[name]=foo
                &topic[name]=bar
        routing:
            # Route your messages to the transports
            'App\Message\SearchForBookInformationMessage': baz

Quick look inside the controller file :

      public function search($isbn) {
            // Wrap the query inside a Message
            $message = new SearchForBookInformationMessage(
                array(
                    'isbn' => $isbn
                ));
            $query = new Envelope($message);

            $query->with(new TransportConfiguration(
                [
                    'topic' => 'bar',
                    'metadata' => [
                        'routingKey' => 'foo.#'
                    ]
                ]
            ));

            $this->messageBus->dispatch($message);
            // ....
      }

But when I try to do so, I get the following error :

In QueueInteropTransportFactory.php line 92:
  [RuntimeException]                                                                                           
  Can't find Enqueue's transport named "default ": Service "enqueue.transport.default .context" is not found.  

What am I doing wrong here ? Does anyone have a working use case for this feature ?

Cheers, Pxl.

PxlCtzn commented 5 years ago

Hi,

After some good sleep and a warm cup of tea, I managed to route my message to the right exchange (topic). The DSN should be inline and not split into multiple line (since YAML spec says the \n will be replace with a space character). So here is my new messenger.yml file :

framework:
    messenger:
        transports:
            amqp_book_search: enqueue://default?queue[name]=foo&queue[bindingKey]=pxlctzn.book_search.%23&topic[name]=book_search&topic[type]=topic

I added the 'lazy' configuration for the Transport inside the controller:

            $query->with(new TransportConfiguration(
                [
                    'topic'     => 'book_search',
                    'metadata'  => 
                    [
                        'routingKey'    => 'pxlctzn.book_search.#',
                        'x-queue-mode'  => 'lazy'
                    ]
                ]
            ));

It's working but not how I expected. Indeed, the message is send thru the right exchange "book_search" but is not ending in the good queue(s). Thus, the message is ending in the "foo" queue (which is created if not found) and not in the queues bound with the 'pxlctzn.book_search.#' routing key. In this case (topic exchange) I don't understand why the queue name is mandatory since the exchange will route the message to the right queue(s) according to the routing key. What did i miss ?

Cheers, Pxl.