objectManager = $objectManager; $this->exchangeFactories = $exchangeFactories; $this->connectionTypeResolver = $connectionTypeResolver; } /** * @inheritdoc * @since 102.0.1 */ public function create($connectionName, array $data = []) { $connectionType = $this->connectionTypeResolver->getConnectionType($connectionName); if (!isset($this->exchangeFactories[$connectionType])) { throw new \LogicException("Not found exchange for connection name '{$connectionName}' in config"); } $factory = $this->exchangeFactories[$connectionType]; $exchange = $factory->create($connectionName, $data); if (!$exchange instanceof ExchangeInterface) { $exchangeInterface = \Magento\Framework\MessageQueue\Bulk\ExchangeInterface::class; throw new \LogicException( "Exchange for connection name '{$connectionName}' " . "does not implement interface '{$exchangeInterface}'" ); } return $exchange; } }