Пример #1
0
 /**
  * @param  Queue $queue
  * @return $this
  */
 public function addQueue(Queue $queue)
 {
     if ($this->hasQueue($queue->name())) {
         throw new \InvalidArgumentException(sprintf('Queue "%s" already defined', $queue->name()));
     }
     $this->queues[$queue->name()] = $queue;
     return $this;
 }
Пример #2
0
 /**
  * @return void
  */
 public function initialize()
 {
     if ($this->initialized) {
         return;
     }
     $this->initialized = true;
     $this->exchange->initialize();
     $this->queue->initialize();
     $this->channel->queue_bind($this->queue->name(), $this->exchange->name());
 }
Пример #3
0
 /**
  *
  */
 public function consume()
 {
     $this->queue->initialize();
     $service = $this->service;
     $this->channel->basic_consume($this->queue->name(), $this->tag, $this->noLocal, $this->noAck, $this->exclusive, $this->noWait, function (AMQPMessage $message) use($service) {
         $ack = $service->execute($message);
         if ($ack === null || $ack === true) {
             $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
         }
     });
     while (count($this->channel->callbacks)) {
         $this->channel->wait();
     }
 }