0

First of all, I am not new to Magento 2 development, I know how to create modules. However, I struggle for 3 days now to get a simple Message Queue in Magento 2 to work. Here are my XML files:

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="erp.queue.order"
           request="string">
        <handler name="erp.queue.order"
                 type="TimoG\OrderTransfer\Model\Queue\Consumer"
                 method="process" />
    </topic>
</config>

queue_consumer.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
    <consumer name="erp.queue.order"
              queue="erp.queue.order"
              connection="db"
              handler="TimoG\OrderTransfer\Model\Queue\Consumer::process"/>
</config>

queue_publisher.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/publisher.xsd">
    <publisher topic="erp.queue.order">
        <connection name="db"
                    exchange="magento-db"
                    disabled="false"/>
    </publisher>
</config>

queue_topology.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
    <exchange name="magento-db"
              type="topic"
              connection="db">
        <binding id="TimoGErpOrderTransfer"
                 topic="erp.queue.order"
                 destinationType="queue"
                 destination="erp.queue.order"/>
    </exchange>
</config>

So adding messages to the queue works (I see it in the database table "queue_message"), however when I execute php bin/magento queue:consumers:start erp.queue.order I always get the following exception:

Type Error occurred when creating object: Magento\Framework\MessageQueue\Consumer\Config\Data, Argume
  nt 2 passed to Magento\Framework\Reflection\TypeProcessor::resolveFullyQualifiedClassName() must be o
  f the type string, null given, called in /Users/timog/Sites/magento2.local/vendor/magento/fra
  mework/Reflection/TypeProcessor.php on line 545

My consumer test code:

<?php

namespace TimoG\OrderTransfer\Model\Queue;

use Exception;
use Psr\Log\LoggerInterface;
use Magento\Framework\Serialize\Serializer\Json;

class Consumer
{

    private $_logger;
    private Json $_json;


    public function __construct(
        LoggerInterface $logger,
        Json $json
    )
    {
        $this->_json = $json;
        $this->_logger = $logger;
    }


    public function process($request)
    {
        try {
            $test = $this->_json->unserialize($request);
        } catch (Exception $exc) {
            $this->_logger->critical($exc->getMessage());
        }
    }
}

I have no idea what's wrong and I really need help please... it's frustrating...

Thank you!

2
  • If you running msg queue in local and your magento is in development mode , then run chmod 777 -R var/ generated after running consumer and try. Commented Jun 8, 2022 at 10:12
  • This is not a permission issue. It definitely has something to do with those files I posted. Commented Jun 8, 2022 at 10:33

1 Answer 1

0

I experienced that same issue, it has something to do with the phpdoc

Try adding string as the $request type.

 public function process(string $request)
 {
        try {
            $test = $this->_json->unserialize($request);
        } catch (Exception $exc) {
            $this->_logger->critical($exc->getMessage());
        }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.