コード例 #1
0
 /**
  * Start a consumer that retrieved documents that have to be saved to the index.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->queue->listen(function ($message) {
         if (strlen($message->body) == 0) {
             $this->queue->rejectMessage($message);
             return;
         }
         $data = json_decode($message->body, true);
         $this->indexer->prepareDocument($message);
         $this->queue->acknowledge($message);
     });
     return 1;
 }
コード例 #2
0
 public function testListen()
 {
     $queueName = 'queue2';
     $callback = new QueueCallableClass();
     $channel = $this->getChannel($queueName, true);
     $channel->expects($this->once())->method('basic_consume')->with($this->equalTo($queueName), $this->equalTo(''), $this->equalTo(false), $this->equalTo(false), $this->equalTo(false), $this->equalTo(false), $callback);
     $connection = $this->getMockBuilder('PhpAmqpLib\\Connection\\AMQPConnection')->disableOriginalConstructor()->setMethods(['channel', 'isConnected', 'close'])->getMock();
     $connection->expects($this->once())->method('channel')->will($this->returnValue($channel));
     $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true));
     $connection->expects($this->once())->method('close');
     $queue = new Queue($connection, $queueName);
     $queue->listen($callback);
 }
コード例 #3
0
 /**
  * Starts to listen to the queue and grabs the messages from the queue to crawl url's.
  *
  * It should endless keep listening to the queue, if the listen function stops, something went wrong
  * so a non-zero integer is returned to indicate something went wrong.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->queue->listen([$this, 'crawlUrl']);
     return 1;
 }