Exemplo n.º 1
0
 private function buildConfig(array $config)
 {
     if (!isset($config['simple_mq'])) {
         throw new SimpleMQException('The configuration key "simple_mq" is missing from the configuration definition');
     }
     $definitions = $config['simple_mq'];
     foreach ($definitions['connections'] as $key => $definition) {
         $this->connections[$key] = new Connection($key, $definition['host'], $definition['port'], $definition['user'], $definition['password'], $definition['vhost']);
     }
     foreach ($definitions['exchanges'] as $k => $ex) {
         $durable = isset($ex['durable']) ? $ex['durable'] : false;
         $exchange = new Exchange($k, $ex['type'], $durable, $this->getConnection($ex['connection']));
         $this->exchanges[$k] = $exchange;
     }
     foreach ($definitions['producers'] as $k => $pr) {
         $rk = isset($pr['routing_key']) ? $pr['routing_key'] : null;
         $autoClose = isset($pr['auto_close']) ? $pr['auto_close'] : false;
         $this->producers[$k] = new Producer($k, $this->getExchange($pr['exchange']), $rk, $autoClose);
     }
     foreach ($definitions['consumers'] as $k => $co) {
         $rk = isset($co['routing_key']) ? $co['routing_key'] : null;
         $autoClose = isset($co['auto_close']) ? $co['auto_close'] : false;
         $queueAutoDelete = isset($co['queue']['auto_delete']) ? $co['queue']['auto_delete'] : false;
         $queueExclusive = isset($co['queue']['exclusive']) ? $co['queue']['exclusive'] : false;
         $queue = new Queue($co['queue']['name'], $co['queue']['durable'], $queueAutoDelete, $queueExclusive);
         $ack = isset($co['ack']) ? $co['ack'] : false;
         $consumer = new Consumer($k, $this->getExchange($co['exchange']), $queue, $rk, $autoClose, $ack);
         if (isset($co['queue']['bindings'])) {
             foreach ($co['queue']['bindings'] as $binding) {
                 $rk = isset($binding['routing_key']) ? $binding['routing_key'] : null;
                 $consumer->addBinding($binding['queue'], $rk);
             }
         }
         $this->consumers[$k] = $consumer;
     }
 }
Exemplo n.º 2
0
 /**
  * @expectedException \GraphAware\SimpleMQ\Exception\SimpleMQException
  */
 public function testRunWillThrowExceptionIfConnectionIsWrong()
 {
     $this->consumer->run();
 }