コード例 #1
0
 /**
  * Start listening on a queue using a messageListener-callback.
  * A successful message consumption is automatically acknowledged.
  *
  * If {@link setTransactional()} is set to TRUE, each message processing is wrapped in a transaction with
  * an explicit commit or rollback on exception.
  *
  * <code>
  * $listener->listen('my_queue', function(\PhpAmqpLib\Message\AMQPMessage $message) {
  *		// process message
  * 		...
  *
  *
  * 		// optional: cancel further listening
  * 		Tx_Amqp_Messaging_AMQPUtils::cancelListening($message);
  * });
  * </code>
  *
  * @param string $queue The name of the queue
  * @param callable $messageListener
  * @throws InvalidArgumentException
  */
 public function listen($queue, Closure $messageListener)
 {
     if ($queue === NULL) {
         throw new \InvalidArgumentException('Queue must not be NULL.');
     }
     $connection = $this->connectionFactory->createConnection();
     $channel = $connection->channel();
     $this->addListener($queue, $channel, $messageListener);
     while (sizeof($channel->callbacks) > 0) {
         $channel->wait();
     }
 }
コード例 #2
0
 protected function getConnection()
 {
     if ($this->connection === NULL) {
         $this->connection = $this->connectionFactory->createConnection();
     }
     return $this->connection;
 }