コード例 #1
0
ファイル: AmqpWrapper.php プロジェクト: ysaroka/uploader
 /**
  * Reconnect amqp connection
  */
 public function reconnect()
 {
     if (!$this->amqpConnection->isConnected()) {
         $this->amqpConnection->reconnect();
         $this->channel = $this->amqpConnection->channel();
         $this->declaredQueues = [];
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function pop(string $queue = null)
 {
     $queue = $this->getQueue($queue);
     try {
         $this->declareQueue($queue);
     } catch (AMQPRuntimeException $exception) {
         $this->connection->reconnect();
         $this->declareQueue($queue);
     }
     // get envelope
     $message = $this->channel->basic_get($queue);
     if ($message instanceof AMQPMessage) {
         return new RabbitMQJob($this->container, $this, $this->channel, $queue, $message);
     }
 }
コード例 #3
0
 /**
  * @param bool $forceReconnection
  *
  * @return void
  */
 public function connect($forceReconnection = false)
 {
     $useSslConnection = !empty($this->sslOptions);
     $env = ['server' => $this->server, 'port' => $this->port, 'vhost' => $this->vhost, 'ssl' => $useSslConnection];
     if (true == $forceReconnection || false == $this->connection instanceof AMQPStreamConnection) {
         $this->logger->debug('Stablishing connection...', $env);
         if ($useSslConnection) {
             $this->connection = new AMQPSSLConnection($this->server, $this->port, $this->user, $this->pass, $this->vhost, $this->sslOptions);
         } else {
             $this->connection = new AMQPStreamConnection($this->server, $this->port, $this->user, $this->pass, $this->vhost);
         }
         $this->logger->info('Connection stablished!', $env);
     } elseif (false == $this->connection->isConnected()) {
         $this->logger->debug('Restablishing connection...', $env);
         $this->connection->reconnect();
         $this->logger->info('Connection restablished!', $env);
     }
     $this->openChannel($forceReconnection);
 }