在Magento2EE中下单时,rabbitmq中的队列订单详细信息

在Magento2EE中下单时,rabbitmq中的队列订单详细信息,rabbitmq,magento2,magento2.1,Rabbitmq,Magento2,Magento2.1,在Magento2EE中,我需要在下订单时立即排队查看订单详细信息。Rabbitmq是我们的消息代理。我已经安装了rabbitmq,并通过以下链接配置了Magento2EE。一切正常。我可以通过提供静态订单ID将订单数组推送到队列中 <?php namespace Inviqa\MessageQueueExample\Console; use Symfony\Component\Console\Command\Command; use Symfony\Component\Consol

在Magento2EE中,我需要在下订单时立即排队查看订单详细信息。Rabbitmq是我们的消息代理。我已经安装了rabbitmq,并通过以下链接配置了Magento2EE。一切正常。我可以通过提供静态订单ID将订单数组推送到队列中

 <?php

namespace Inviqa\MessageQueueExample\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\MessageQueue\PublisherInterface;
use Inviqa\MessageQueueExample\Api\MessageInterface;
use Magento\Sales\Model\Order;

class MessagePublishCommand extends Command
{
    const COMMAND_QUEUE_MESSAGE_PUBLISH = 'queue:message:publish';
    const MESSAGE_ARGUMENT = 'message';
    const TOPIC_ARGUMENT = 'topic';

    /**
     * @var PublisherInterface
     */
    protected $publisher;
    protected $order;


    /**
     * @var string
     */
    protected $message;

    /**
     * {@inheritdoc}
     */
    public function __construct(
        PublisherInterface $publisher,
        MessageInterface $message,
        Order $order,
        $name = null
    ) {
        $this->publisher = $publisher;
        $this->message = $message;
        $this->order = $order;
        parent::__construct($name);
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $message = $input->getArgument(self::MESSAGE_ARGUMENT);
        $topic = $input->getArgument(self::TOPIC_ARGUMENT);

        try {

            $_orderId = 000000004; 
            $_order = $this->order->load($_orderId);
            $_items = $_order->getAllVisibleItems();
            foreach ($_items as $_item) {
                $_orderItems[] = [
                    'sku' => $_item->getSku(), 
                    'item_id' => $_item->getId(),
                    'price' => $_item->getPrice(),
                ];

            }
            $message = $_orderItems;

            $this->message->setMessage($message);
            $this->publisher->publish($topic, $this->message);
            /*print_r($message);
            die;*/
           // $output->writeln(sprintf('Published message "%s" to topic "%s"', $message, $topic));
            $output->writeln(sprintf('Published order'));

        } catch (\Exception $e) {
            $output->writeln($e->getMessage());
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this->setName(self::COMMAND_QUEUE_MESSAGE_PUBLISH);
        $this->setDescription('Publish a message to a topic');
        $this->setDefinition([
            new InputArgument(
                self::MESSAGE_ARGUMENT,
                InputArgument::REQUIRED,
                'Message'
            ),
            new InputArgument(
                self::TOPIC_ARGUMENT,
                InputArgument::REQUIRED,
                'Topic'
            ),
        ]);
        parent::configure();
    }
}