Ejemplo n.º 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);
 }