/**
  * Actual health check logic.
  *
  * @param HealthBuilder $builder
  *
  * @throws \Exception any Exception that should create a Status::DOWN
  *                    system status.
  */
 protected function doHealthCheck(HealthBuilder $builder)
 {
     try {
         $this->connection->reconnect();
         $serverProperties = $this->connection->getServerProperties();
         $builder->withDetail('version', $serverProperties['version'][1]);
     } catch (\Exception $e) {
         $builder->down($e);
         return;
     }
     $builder->up();
 }
예제 #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);
     }
 }
예제 #3
0
 /**
  * @param AbstractConnection|null $connection
  *
  * @return $this
  */
 public function connect($connection = null)
 {
     if (null !== $connection) {
         $this->setConnection($connection);
     }
     // The connection is opened when the connection object is created, we just need to check if this is true
     // Calling getConnection() creates a new connection if one doesn't exist
     if (!$this->getConnection()->isConnected()) {
         $this->connection->reconnect();
     }
     return $this;
 }
 /**
  * Perform the test after the connection has already been setup
  */
 protected function performTest()
 {
     // We need to a channel and exchange/queue
     $this->setupChannel();
     // Ensure normal publish then get works
     $this->assertEquals($this->msgBody, $this->publishGet()->body);
     // Reconnect the socket/stream connection
     $this->conn->reconnect();
     // Setup the channel and declarations again
     $this->setupChannel();
     // Ensure normal publish then get works (after reconnect attempt)
     $this->assertEquals($this->msgBody, $this->publishGet()->body);
 }
예제 #5
0
 /**
  * @inheritdoc
  */
 public function reconnect() : bool
 {
     $this->connection->reconnect();
     return $this->isConnected();
 }