0

Magento Commerce comes with a RabbitMq integration.

I'm trying to publish smth in RabbitMq. I'm following the docs on this.

Problem: I get the following exception:

Fatal error: Uncaught PhpAmqpLib\Exception\AMQPProtocolChannelException: NOT_FOUND - no exchange 'vulpea-test' in vhost '/' in /var/www/magento/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php on line 191

Looking in RabbitMq the exchange does not exist. But Magento Should create it when making the request. If I create the exchange by hand the exception does not appear anymore yet messages are not published either way.

Note: I can consume queues successfully. And I have no errors at setup:di:compile.

communication.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Communication/etc/communication.xsd">
    <topic
            name="vulpea.test"
            request="Vulpea\Test\Model\Message"
    />
</config>

queue.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/queue.xsd">
    <broker topic="vulpea.test" type="amqp" exchange="vulpea-test">
        <queue
                consumer="vulpeaTest"
                name="vulpea-test"
                consumerInstance="Magento\Framework\MessageQueue\Consumer"
        />
    </broker>
</config>

Controller

namespace Vulpea\Test\Controller\Test;

use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\MessageQueue\PublisherInterface;
use Vulpea\Test\Model\Message;


    class Rabbit extends \Magento\Framework\App\Action\Action
    {
        protected $publisher;


        public function __construct(
            PublisherInterface $publisher,
            Context $context
        )
        {
            $this->publisher = $publisher;
            parent::__construct($context);
        }

        /**
         * Dispatch request
         *
         * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
         * @throws \Magento\Framework\Exception\NotFoundException
         */
        public function execute()
        {
            try{
                $message = new Message();
                $message->setMessage('Mesage');

                $this->publisher->publish("vulpea.test", $message);
            }catch (\Exception $exception){
                var_dump($exception->getMessage());
            }

            var_dump("It works");
            exit;
        }
    }

Any pointers are welcomed. Thanks

2

Ok. So it turns out that exchanges,queues etc. are created only when setup:upgrade command is run.

If you arrive here, you might want to write that down because it's not mentioned in the docs (Or at least I could not find it anywhere).

0

I was clueless on the error and was struggling to find the answer. Adding the problem here so that someone searching for similar problem will be able to find it. Thanks to vitoriodachef for the solution :

=INFO REPORT==== 3-Sep-2018::13:34:12 === accepting AMQP connection <0.1267.0> (127.0.0.1:43868 -> 127.0.0.1:5672)

=ERROR REPORT==== 3-Sep-2018::13:34:12 === Channel error on connection <0.1267.0> (127.0.0.1:43868 -> 127.0.0.1:5672, vhost: '/', user: 'admin'), channel 1: operation basic.publish caused a channel exception not_found: "no exchange 'magento' in vhost '/'"

=INFO REPORT==== 3-Sep-2018::13:34:12 === closing AMQP connection <0.1267.0> (127.0.0.1:43868 -> 127.0.0.1:5672)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.