/** * Connect to AMQP server * * @param array $config * @throws \Deliveries\Exceptions\BrokerException * @return \Pheanstalk\Pheanstalk */ public function connect(array $config) { $host = empty($config['host']) === true ? self::DEFAULT_HOST : $config['host']; $port = empty($config['port']) === true ? self::DEFAULT_PORT : $config['port']; $timeout = empty($config['timeout']) === true ? self::DEFAULT_TIMEOUT : $config['timeout']; $persistent = empty($config['persistent']) === true ? self::DEFAULT_IS_PERSISTENT : $config['persistent']; $this->broker = new QueueBroker($host, $port, $timeout, $persistent); /** @noinspection PhpUndefinedMethodInspection */ $isConnect = $this->broker->getConnection()->isServiceListening(); if (!$isConnect) { throw new BrokerException('Queue connection failed! Check configurations'); } return $this; }
protected function setUp() { $pheanstalk = new Pheanstalk(getenv('BEANSTALK_HOST')); if (!$pheanstalk->getConnection()->isServiceListening()) { $this->markTestSkipped('Beanstalk service is not available.'); } }