Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
8 
11 
17 class Config implements ConfigInterface
18 {
22  protected $queueConfigData;
23 
27  public function __construct(Config\Data $queueConfigData)
28  {
29  $this->queueConfigData = $queueConfigData;
30  }
31 
35  public function getExchangeByTopic($topicName)
36  {
37  $publisherConfig = $this->getPublisherConfigByTopic($topicName);
38  return isset($publisherConfig[ConfigInterface::PUBLISHER_EXCHANGE])
39  ? $publisherConfig[ConfigInterface::PUBLISHER_EXCHANGE]
40  : null;
41  }
42 
46  public function getQueuesByTopic($topic)
47  {
48  $publisherConfig = $this->getPublisherConfigByTopic($topic);
49  $exchange = isset($publisherConfig[ConfigInterface::PUBLISHER_NAME])
50  ? $publisherConfig[ConfigInterface::PUBLISHER_NAME]
51  : null;
56  $bindKey = $exchange . '--' . $topic;
57  $output = $this->queueConfigData->get(ConfigInterface::EXCHANGE_TOPIC_TO_QUEUES_MAP . '/' . $bindKey);
58  if (!$output) {
59  throw new LocalizedException(
60  new Phrase(
61  'No bindings configured for the "%topic" topic at "%exchange" exchange.',
62  ['topic' => $topic, 'exchange' => $exchange]
63  )
64  );
65  }
66  return $output;
67  }
68 
72  public function getConnectionByTopic($topic)
73  {
74  try {
75  $publisherConfig = $this->getPublisherConfigByTopic($topic);
76  } catch (\Magento\Framework\Exception\LocalizedException $e) {
77  return null;
78  }
79  return isset($publisherConfig[ConfigInterface::PUBLISHER_CONNECTION])
80  ? $publisherConfig[ConfigInterface::PUBLISHER_CONNECTION]
81  : null;
82  }
83 
87  public function getConnectionByConsumer($consumer)
88  {
89  $connection = $this->queueConfigData->get(
91  );
92  if (!$connection) {
93  throw new LocalizedException(
94  new Phrase('Consumer "%consumer" has not connection.', ['consumer' => $consumer])
95  );
96  }
97  return $connection;
98  }
99 
103  public function getMessageSchemaType($topic)
104  {
105  return $this->queueConfigData->get(
108  );
109  }
110 
114  public function getConsumerNames()
115  {
116  $queueConfig = $this->queueConfigData->get(ConfigInterface::CONSUMERS, []);
117  return array_keys($queueConfig);
118  }
119 
123  public function getConsumer($name)
124  {
125 
126  return $this->queueConfigData->get(ConfigInterface::CONSUMERS . '/' . $name);
127  }
128 
132  public function getBinds()
133  {
134  return $this->queueConfigData->get(ConfigInterface::BINDS, []);
135  }
136 
140  public function getPublishers()
141  {
142  return $this->queueConfigData->get(ConfigInterface::PUBLISHERS, []);
143  }
144 
148  public function getConsumers()
149  {
150  return $this->queueConfigData->get(ConfigInterface::CONSUMERS, []);
151  }
152 
156  public function getTopic($name)
157  {
158  return $this->queueConfigData->get(ConfigInterface::TOPICS . '/' . $name);
159  }
160 
164  public function getPublisher($name)
165  {
166  return $this->queueConfigData->get(ConfigInterface::PUBLISHERS . '/' . $name);
167  }
168 
172  public function getResponseQueueName($topicName)
173  {
174  return ConfigInterface::RESPONSE_QUEUE_PREFIX . str_replace('-', '_', $topicName);
175  }
176 
184  protected function getPublisherConfigByTopic($topicName)
185  {
186  $publisherName = $this->queueConfigData->get(
188  );
189 
190  if (!$publisherName) {
191  throw new LocalizedException(
192  new Phrase('Message queue topic "%topic" is not configured.', ['topic' => $topicName])
193  );
194  }
195 
196  $publisherConfig = $this->queueConfigData->get(ConfigInterface::PUBLISHERS . '/' . $publisherName);
197  if (!$publisherConfig) {
198  throw new LocalizedException(
199  new Phrase(
200  'Message queue publisher "%publisher" is not configured.',
201  ['publisher' => $publisherName]
202  )
203  );
204  }
205  return $publisherConfig;
206  }
207 }
__construct(Config\Data $queueConfigData)
Definition: Config.php:27
$connection
Definition: bulk.php:13
if(!isset($_GET['name'])) $name
Definition: log.php:14