Пример #1
0
 /**
  * Create new instance from options
  *
  * @param NotificationInterface $notification
  * @param array                 $options
  *
  * @return Amqp
  */
 public static function create(NotificationInterface $notification, array $options = array())
 {
     $options += array('host' => '127.0.0.1', 'port' => 5672, 'vhost' => '/', 'login' => 'guest', 'password' => 'guest', 'queue_name' => 'apn.push.queue', 'publish_options' => array(), 'publish_flag' => AMQP_NOPARAM);
     // Create AMQP Connection
     $amqpConnection = new \AMQPConnection(array('host' => $options['host'], 'port' => $options['port'], 'vhost' => $options['vhost'], 'login' => $options['login'], 'password' => $options['password']));
     $amqpConnection->connect();
     // Create AMQP Channel
     $channel = new \AMQPChannel($amqpConnection);
     // Create exchange
     $exchange = new \AMQPExchange($channel);
     // Create queue
     $queue = new \AMQPQueue($channel);
     $queue->setName($options['queue_name']);
     /** @see https://github.com/pdezwart/php-amqp/pull/58 */
     $queue->declareQueue();
     // Create amqp adapter
     $adapter = new AmqpAdapter();
     $adapter->setRoutingKey($options['queue_name'])->setPublishFlag($options['publish_flag'])->setPublishOptions($options['publish_options'])->setExchange($exchange)->setQueue($queue);
     /** @var Amqp $amqp */
     $amqp = new static();
     $amqp->setNotification($notification)->setAdapter($adapter);
     return $amqp;
 }
Пример #2
0
 /**
  * Test get message with error: Queue not found
  *
  * @expectedException \RuntimeException
  */
 public function testGetMessageQueueNotFound()
 {
     $adapter = new AmqpAdapter();
     $adapter->getMessage();
 }