Exchange.php 1.3 KB

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