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