Example #1
0
 public function run(Process $process)
 {
     $totalProcessed = 0;
     $this->setProcessTitle($process, 'waiting first envelope');
     $broker = new AmqpBroker($this->config);
     $broker->getConsumer($this->name)->consume(function (\AMQPEnvelope $envelope, \AMQPQueue $queue) use($process, &$totalProcessed) {
         $process->dispatchSignals();
         $this->setProcessTitle($process, 'processing `' . $envelope->getRoutingKey() . '`');
         try {
             /** @var $executor ActionInterface */
             $executor = new $this->executorClass();
             $executor->execute($envelope, $queue);
             $queue->ack($envelope->getDeliveryTag());
         } catch (\Exception $e) {
             $queue->nack($envelope->getDeliveryTag(), \AMQP_REQUEUE);
             throw $e;
         }
         if ($process->isShouldShutdown()) {
             $this->setProcessTitle($process, 'canceling');
             $queue->cancel();
             return false;
         }
         $this->setProcessTitle($process, 'waiting next envelope (processed ' . ++$totalProcessed . ')');
         return true;
     });
 }
Example #2
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testThrowsExceptionOnUnknownConsumer()
 {
     $broker = new AmqpBroker(['connections' => []]);
     $broker->getConsumer('test');
 }