Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConsumerConfiguration.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\MessageQueue\ConfigInterface as MessageQueueConfig;
10 use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
11 
16 {
21  const CONSUMER_TYPE = "consumer_type";
22 
27  const HANDLERS = 'handlers';
28 
32  private $data;
33 
37  private $queueRepository;
38 
42  private $consumerConfig;
43 
47  private $communicationConfig;
48 
58  public function __construct(QueueRepository $queueRepository, MessageQueueConfig $messageQueueConfig, $data = [])
59  {
60  $this->data = $data;
61  $this->queueRepository = $queueRepository;
62  }
63 
67  public function getConsumerName()
68  {
69  return $this->getData(self::CONSUMER_NAME);
70  }
71 
75  public function getMaxMessages()
76  {
77  return $this->getData(self::MAX_MESSAGES);
78  }
79 
83  public function getQueueName()
84  {
85  return $this->getData(self::QUEUE_NAME);
86  }
87 
91  public function getType()
92  {
93  $topics = $this->getData(self::TOPICS);
94  if (count($topics) > 1) {
95  throw new \LogicException(
96  'Current method is deprecated and does not support more than 1 topic declarations for consumer. '
97  . 'Use \Magento\Framework\MessageQueue\ConsumerConfiguration::getConsumerType instead. '
98  . "Multiple topics declared for consumer '{$this->getConsumerName()}'"
99  );
100  } elseif (count($topics) < 1) {
101  throw new \LogicException(
102  "There must be at least one topic declared for consumer '{$this->getConsumerName()}'."
103  );
104  }
105  // Get the only topic and read consumer type from its declaration. Necessary for backward compatibility
106  $topicConfig = reset($topics);
107  return $topicConfig[self::TOPIC_TYPE];
108  }
109 
113  public function getHandlers($topicName)
114  {
115  return $this->getTopicConfig($topicName)[self::TOPIC_HANDLERS];
116  }
117 
121  public function getTopicNames()
122  {
123  $topics = $this->getData(self::TOPICS);
124  return is_array($topics) && count($topics) ? array_keys($topics) : [];
125  }
126 
130  public function getQueue()
131  {
132  $connectionName = $this->getConsumerConfig()->getConsumer($this->getConsumerName())->getConnection();
133  return $this->queueRepository->get($connectionName, $this->getQueueName());
134  }
135 
139  public function getMessageSchemaType($topicName)
140  {
141  return $this->getCommunicationConfig()->getTopic($topicName)[CommunicationConfig::TOPIC_REQUEST_TYPE];
142  }
143 
150  private function getTopicConfig($topicName)
151  {
152  if (!isset($this->getData(self::TOPICS)[$topicName])) {
153  throw new \LogicException("Consumer configuration for {$topicName} topic not found.");
154  }
155  return $this->getData(self::TOPICS)[$topicName];
156  }
157 
164  private function getData($key)
165  {
166  if (!isset($this->data[$key])) {
167  return null;
168  }
169  return $this->data[$key];
170  }
171 
179  private function getConsumerConfig()
180  {
181  if ($this->consumerConfig === null) {
182  $this->consumerConfig = \Magento\Framework\App\ObjectManager::getInstance()->get(ConsumerConfig::class);
183  }
184  return $this->consumerConfig;
185  }
186 
194  private function getCommunicationConfig()
195  {
196  if ($this->communicationConfig === null) {
197  $this->communicationConfig = \Magento\Framework\App\ObjectManager::getInstance()
198  ->get(CommunicationConfig::class);
199  }
200  return $this->communicationConfig;
201  }
202 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(QueueRepository $queueRepository, MessageQueueConfig $messageQueueConfig, $data=[])