コード例 #1
0
 /**
  * Executes the current command.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return integer 0 if everything went fine, or an error code
  *
  * @throws \InvalidArgumentException When the number of messages to consume is less than 0
  * @throws \BadFunctionCallException When the pcntl is not installed and option -s is true
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (defined('AMQP_DEBUG') === false) {
         define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     }
     $this->amount = $input->getOption('messages');
     if (0 > $this->amount) {
         throw new \InvalidArgumentException("The -m option should be null or greater than 0");
     }
     $this->consumer = $this->getConsumerInstance($input);
     if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) {
         $this->consumer->setMemoryLimit($input->getOption('memory-limit'));
     }
     $this->consumer->setRoutingKey($input->getOption('route'));
     $this->consumer->consume($this->amount);
 }
コード例 #2
0
ファイル: CommandConsumer.php プロジェクト: wizbii/pipeline
 public function consume($msgAmount)
 {
     try {
         parent::consume($msgAmount);
         $this->consumeRetryCount = 0;
     } catch (\Exception $e) {
         $this->consumeRetryCount++;
         if ($this->consumeRetryCount < 10) {
             parent::consume($msgAmount);
             return;
         }
         throw $e;
     }
 }
コード例 #3
0
ファイル: Consumer.php プロジェクト: bazitov/kueueingbundle
 /**
  * Overridden to add support for timeout
  * @param int $msgAmount
  * @param int $timeout
  */
 public function consume($msgAmount, $timeout = 0)
 {
     if ($timeout > 0) {
         // save initial time
         $loopBegin = time();
         $remaining = $timeout;
         // reimplement parent::consume() to inject the timeout
         $this->target = $msgAmount;
         $this->setupConsumer();
         while (count($this->getChannel()->callbacks)) {
             // avoid waiting more than timeout seconds for message reception
             $this->setIdleTimeout($remaining);
             $this->maybeStopConsumer();
             try {
                 $this->getChannel()->wait(null, true, $this->getIdleTimeout());
             } catch (AMQPTimeoutException $e) {
                 return;
             }
             $remaining = $loopBegin + $timeout - time();
             if ($remaining <= 0) {
                 $this->forceStopConsumer();
             }
         }
     } else {
         $this->loopBegin = null;
         parent::consume($msgAmount);
     }
 }