Question

How to publish message to rabbitmq and read message in consumer and create a bulk products in magento while running custom queue in rabbitmq.

I want to create custom module in magento 2.3 beta to track the publisher message and processing message in consumer

Was it helpful?

Solution

I am currently implementing bulk API for products and i have created custom module for it. I had to create custom module because i receive product data from a source does not have all attributes i wanted to create a product in magento. In my module i have a function that will push product data to RabbitMQ. My function will look as below:

private function bulkPublish($products, $topic)
{
    $inputProcessed = [];
    foreach ($products as $key => $singleEntityParams) {
        $inputProcessed[$key] = $this->inputProcessor->process(
            'Magento\Catalog\Api\ProductRepositoryInterface',
            'save',
            $singleEntityParams
        );

    }
    $result = null;

    try {

        $result = $this->massSchedule->publishMass($topic, $inputProcessed)->getBulkUuid();
        //$result = $this->massSchedule->publishMass($topic, $inputProcessed)->getBulkUuid();
    } catch (Exception $e) {
        echo $e->getMessage();
        echo $e->getTraceAsString();

    }
    return $result;

}

Where: $this->inputProcessor = InpMagento\Framework\Webapi\ServiceInputProcessor; $this->massSchedule = Magento\AsynchronousOperations\Model\MassSchedule; $topic = async.magento.catalog.api.productrepositoryinterface.save.put ; $products = Formatted data based on requirement for magento API

Following command should read message from RabbitMq:

php bin/magento queue:consumers:start async.operations.all

You might run this as a cron job or anyway you want.

I know this is late to answer but adding here so that other can use if they want.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top