1

Is there a way to retrieve queued messages in 2.4 code wise without the need to depend on what queue type is used (RabbitMq or db queue) for a specific topic?
I know that when using the db queue system I can query the queue_message table, but I don't want to depend on the queue engine used.
I also don't want to start processing the messages. I want just to check they are there in the queue.
So is there a method (class / interface) which achieves something like

$topicName = 'my.own.topic';
$queuedMessages = $something->getMessages($topic);

2 Answers 2

2

If you want just to check if there are any messages in queue, you can use CheckIsAvailableMessagesInQueue class

Also in Magento framework that build as analog of AMQP protocol, there are no guaranties that specific topic will deliver messages just to one queue.

But you can get all queues name from topology configuration

See

\Magento\Framework\MessageQueue\Topology\ConfigInterface::getExchange() -> \Magento\Framework\MessageQueue\Topology\Config\ExchangeConfigItemInterface::getBindings() -> \Magento\Framework\MessageQueue\Topology\Config\ExchangeConfigItem\BindingInterface::getDestination()/ \Magento\Framework\MessageQueue\Topology\Config\ExchangeConfigItem\BindingInterface::getTopic()

0
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $consumerModel = $objectManager->create(\Magento\MysqlMq\Model\ResourceModel\Queue::class);
    $data = $consumerModel->getMessages('custom_import_products');

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.