예제 #1
0
 public function disconnect()
 {
     if (!$this->amqp_connection) {
         return;
     }
     if ($this->amqp_connection->isConnected()) {
         $this->amqp_connection->close();
     }
     $this->amqp_connection = null;
 }
예제 #2
0
 /**
  * @return \PhpAmqpLib\Channel\AMQPChannel
  */
 public function channel()
 {
     try {
         // Create channel
         if ($this->channel === null) {
             // Connect if not connected
             if (!$this->connection->isConnected()) {
                 $this->connection->reconnect();
             }
             // Create channel
             $this->channel = $this->getConnection()->channel();
         }
         return $this->channel;
     } catch (\Exception $e) {
         // The exceptions thrown by the library are cryptic at best. You may very well get seemingly unrelated a protocol error etc.
         // Throw a more descriptive exception.
         throw new \InvalidArgumentException("Failed to create the AMQP channel. This may be related to a misconfiguration of the connection or channel.", 0, $e);
     }
 }
 public function isConnected()
 {
     return $this->connection && $this->connection->isConnected();
 }
예제 #4
0
 /**
  * @inheritdoc
  */
 public function isConnected() : bool
 {
     return $this->connection->isConnected();
 }