exchangeRepository = $exchangeRepository; $this->envelopeFactory = $envelopeFactory; $this->messageEncoder = $messageEncoder; $this->messageValidator = $messageValidator; } //@codingStandardsIgnoreEnd /** * {@inheritdoc} */ public function publish($topicName, $data) { $this->messageValidator->validate($topicName, $data); $data = $this->messageEncoder->encode($topicName, $data); $replyTo = $this->getResponseQueueNameBuilder()->getQueueName($topicName); $envelope = $this->envelopeFactory->create( [ 'body' => $data, 'properties' => [ 'reply_to' => $replyTo, 'delivery_mode' => 2, 'correlation_id' => rand(), 'message_id' => md5(uniqid($topicName)) ] ] ); $connectionName = $this->getPublisherConfig()->getPublisher($topicName)->getConnection()->getName(); $exchange = $this->exchangeRepository->getByConnectionName($connectionName); $responseMessage = $exchange->enqueue($topicName, $envelope); return $this->messageEncoder->decode($topicName, $responseMessage, false); } /** * Get response queue name builder. * * @return ResponseQueueNameBuilder * * @deprecated 102.0.1 */ private function getResponseQueueNameBuilder() { if ($this->responseQueueNameBuilder === null) { $this->responseQueueNameBuilder = \Magento\Framework\App\ObjectManager::getInstance() ->get(ResponseQueueNameBuilder::class); } return $this->responseQueueNameBuilder; } /** * Get publisher config. * * @return PublisherConfig * * @deprecated 102.0.1 */ private function getPublisherConfig() { if ($this->publisherConfig === null) { $this->publisherConfig = \Magento\Framework\App\ObjectManager::getInstance()->get(PublisherConfig::class); } return $this->publisherConfig; } }