1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\MysqlMq\Model\Driver;
use Magento\Framework\MessageQueue\EnvelopeInterface;
use Magento\Framework\MessageQueue\ExchangeInterface;
use Magento\Framework\MessageQueue\ConfigInterface as MessageQueueConfig;
use Magento\MysqlMq\Model\QueueManagement;
class Exchange implements ExchangeInterface
{
/**
* @var MessageQueueConfig
*/
private $messageQueueConfig;
/**
* @var QueueManagement
*/
private $queueManagement;
/**
* Initialize dependencies.
*
* @param MessageQueueConfig $messageQueueConfig
* @param QueueManagement $queueManagement
*/
public function __construct(MessageQueueConfig $messageQueueConfig, QueueManagement $queueManagement)
{
$this->messageQueueConfig = $messageQueueConfig;
$this->queueManagement = $queueManagement;
}
/**
* Send message
*
* @param string $topic
* @param EnvelopeInterface $envelope
* @return mixed
*/
public function enqueue($topic, EnvelopeInterface $envelope)
{
$queueNames = $this->messageQueueConfig->getQueuesByTopic($topic);
$this->queueManagement->addMessageToQueues($topic, $envelope->getBody(), $queueNames);
return null;
}
}