コード例 #1
0
 /**
  * Create an exception that indicates an unexpected closure of the
  * connection to the AMQP broker.
  *
  * @param ConnectionOptions $options  The options used when establishing the connection.
  * @param Exception|null    $previous The exception that caused this exception, if any.
  */
 public static function closedUnexpectedly(ConnectionOptions $options, Exception $previous = null) : SingleConnectionException
 {
     return new self($options, \sprintf('The AMQP connection with broker [%s:%d] was closed unexpectedly.', $options->host(), $options->port()), $previous);
 }
コード例 #2
0
ファイル: DirectConnector.php プロジェクト: recoilphp/amqp
 /**
  * Determine the connection timeout to used based on the connection options
  * and PHP settings.
  */
 private function connectionTimeout(ConnectionOptions $options) : float
 {
     $connectionTimeout = $options->advancedConnectionOptions()->connectionTimeout();
     if ($connectionTimeout !== null) {
         return $connectionTimeout;
     }
     $connectionTimeout = ini_get('default_socket_timeout');
     if ($connectionTimeout !== false) {
         return (double) $connectionTimeout;
     }
     return self::DEFAULT_CONNECTION_TIMEOUT;
 }
コード例 #3
0
ファイル: HandshakeManager.php プロジェクト: recoilphp/amqp
 /**
  * Perform the "open" phase of the handshake.
  *
  * @recoil-coroutine
  *
  * @param DuplexChannel     $frames  A channel over which frames are sent
  *                                   and received.
  * @param ConnectionOptions $options The options used when establishing
  *                                   the connection.
  */
 private function open(DuplexChannel $frames, ConnectionOptions $options) : Generator
 {
     (yield $frames->write(ConnectionOpenFrame::create($options->vhost())));
     try {
         $frame = (yield $frames->read());
     } catch (ChannelClosedException $e) {
         throw SingleConnectionException::authorizationFailed($options, $e);
     }
     if ($frame instanceof ConnectionCloseFrame) {
         if ($frame->replyCode === Constants::NOT_ALLOWED && $frame->classId === ConnectionOpenFrame::METHOD_ID >> 16 && $frame->methodId === (ConnectionOpenFrame::METHOD_ID & 0xff)) {
             throw SingleConnectionException::authorizationFailed($options);
         }
         throw SingleConnectionException::closedUnexpectedly($options);
     } elseif (!$frame instanceof ConnectionOpenOkFrame) {
         throw ProtocolException::unexpectedFrame($frame, 'expected ' . ConnectionOpenOkFrame::class);
     }
 }