Skip to content

Getting Error when consume the queue data RabbitMQ – Magento2.4.5

I have implemented 2 queues, one for primary queue and one for retry queue.
Primary queue – Publish data & Consume data is working properly, but when i implementing 2nd queue for retry and when i consume the first queue i got the error of

Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of ‘256’ frames

Below is the my code in my custom module:

Communication.xml

<topic name="order.send" request="string"/>
<topic name=order.retry.send" request="string"/>

queue_consumer.xml

 <consumer name="order.send" queue="order.send"
                  connection="amqp" maxMessages="10"
                  handler="VendorModuleApiOrderApiInterface::process"/>
 <consumer name="order.retry.send" queue="order.retry.send"
                  connection="amqp" maxMessages="10"
                  consumerInstance="MagentoFrameworkMessageQueueConsumer" handler="VendorModuleModelMessageQueueConsumerRetrySendPayloadConsumer::execute" />

queue_publisher.xml

<publisher topic="order.send">
    <connection name="amqp" exchange="magento-amqp" />
</publisher>
<publisher topic="order.retry.send">
    <connection name="amqp" exchange="magento-amqp" />
</publisher>

queue_topology.xml

<exchange name="magento-amqp" type="topic" connection="amqp">
    <binding id="sendOrderData" topic="order.send" destinationType="queue"
             destination="order.send"/>
    <binding id="sendPayloadRetry" topic="order.retry.send"
             destinationType="queue" destination="order.retry.send"/>
</exchange>

From frontend on order place observer i have publish the record in the “order.send” queue like below code and it is working properly.

OrderplaceObserver.php

try{
      $this->_publisher->publish('order.send', $this->_json->serialize($finalOrderArray));
   } catch (Exception $e) {
      }

Below is my consumer file (Model file) as defined in the queue_consumer.xml

OrderApi.php

use MagentoFrameworkMessageQueuePublisherInterface;
use VendorModuleModelRetryQueuePublish;   

/**
     * @var RetryQueuePublish
     */
    protected $_retryPublisher;

public function __construct(
        RetryQueuePublish $retryPublisher,
        PublisherInterface $publisher,
){
        $this->_retryPublisher = $retryPublisher;
        $this->_publisher = $publisher;
}


    public function process($message)
        {
            
            $testMode = $this->_scopeConfig->getValue('config/group/testmode', MagentoStoreModelScopeInterface::SCOPE_STORE, $this->helper->getStoreId());
            
            if($testMode == 1){
                //$this->_publisher->publish('order.retry.send', $this->json->serialize($message));
                $this->_retryPublisher->execute($message);
            }
    try {
                $data = $this->json->unserialize($message);
                $this->makeApiCall($data, 'orderPush');
            } catch (Exception $ex) {
                return false;
            }

RetryQueuePublish.php

class RetryQueuePublish implements RetryQueuePublishInterface
{
    const RETRY_TOPIC_NAME = 'order.retry.send';

  public function execute($data)
    {
        try{
            //function execute handles saving order object to table
            $this->publisher->publish(self::RETRY_TOPIC_NAME, $data);

    }catch (Exception $e){
        //logic to catch and log errors
        //$this->_logger->critical($e->getMessage());
    }
   }
}

So as per above example code i call the retry queue from my primary consumer file, so whenever i call my primary consumer to consume message i got an error of

Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of ‘256’ frames

I don’t know what exactly what i am doing wrong, but when i doing regular publisher from magento publish into retry queue it is working when i call the another model for publish message into Retry queue it is giving above error, please review my code in orderApi.php file and process function in which i have written code.

Please help me here, so i was looking for any solution here.

Thank you in advance.