/**
  * @test createDelivery create delivery from amqp lib message delivery_info
  */
 public function deliveryInfo()
 {
     $amqpLibMessage = new AmqpLibMessage('body content');
     $amqpLibMessage->delivery_info = ['delivery_tag' => '12345', 'exchange' => 'foo.bar', 'routing_key' => 'foo.#', 'redelivered' => true];
     $delivery = AmqpMessageUtils::createDelivery($amqpLibMessage, 'foo');
     $this->assertEquals('foo', $delivery->getQueue());
     $this->assertEquals('body content', $delivery->getMessage()->getBody());
     $this->assertEquals('12345', $delivery->getTag());
     $this->assertEquals('foo.bar', $delivery->getExchange());
     $this->assertEquals('foo.#', $delivery->getRoutingKey());
     $this->assertTrue($delivery->isRedelivered());
 }
 /**
  * {@inheritDoc}
  */
 public function consume($queue, callable $callback, $timeout)
 {
     // Zero timeout = do not return, select functions expect null for it
     if ($timeout == 0) {
         $timeout = null;
     }
     try {
         $active = true;
         $channel = $this->getChannel();
         $tag = $channel->basic_consume($queue, '', false, false, false, false, function (AMQPLibMessage $msg) use(&$active, $callback, $channel, $queue) {
             if (!$callback(AmqpMessageUtils::createDelivery($msg, $queue))) {
                 // Stop consuming
                 $active = false;
             }
         });
         while ($active) {
             $changedStreams = @$this->getConnection()->select($timeout);
             if (false === $changedStreams) {
                 $error = error_get_last();
                 // Check if we got interruption from system call, ex. on signal
                 // On some php version (ex. php 5.5 error is null on interrupted system call)
                 if ($error === null || stripos($error['message'], 'interrupted system call') !== false || $error['type'] !== E_ERROR || $error['type'] !== E_WARNING) {
                     break;
                 }
                 throw new \RuntimeException('Error while waiting on stream', 0, new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
             } elseif ($changedStreams > 0) {
                 $channel->wait();
             } else {
                 break;
             }
         }
         // Cancel consumer and close channel
         $channel->basic_cancel($tag);
         $this->closeChannel();
     } catch (\Exception $e) {
         throw new DriverException('Basic consume error', $e);
     }
 }