【问题标题】:How to check connection errors to RabbitMQ?如何检查到 RabbitMQ 的连接错误?
【发布时间】:2019-06-19 14:19:17
【问题描述】:

我已经安装了 RabbitMQ,并且能够成功启动连接。我是这样做的:

    require_once __DIR__ . '/vendor/autoload.php';
    use PhpAmqpLib\Connection\AMQPStreamConnection;
    use PhpAmqpLib\Message\AMQPMessage;
    $connection = new AMQPStreamConnection($config_hostnameRabbitmqConnection, $config_portRabbitmqConnection, $config_usernameRabbitmqConnection, $config_passwordRabbitmqConnection);
    $channel = $connection->channel();

我试图在出现问题的情况下捕获错误。如果没有建立连接,在这种情况下怎么办?我通常使用 empty() 、 isset() 和 try and catch 方式检查内容。然而,在这种情况下,实际上并没有什么东西可以检查是否有空。在这种情况下,我是使用 try and catch 还是有其他更好的方法?

【问题讨论】:

    标签: php rabbitmq


    【解决方案1】:

    我认为 RabbitMQ 没有处理错误的默认方式。你可以这样做

        try {
          $channel = $connection->channel();
        } catch (Exception $e) {
            die("I could not create a connection");
        }
    

    这就是你要找的吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 2011-09-30
      相关资源
      最近更新 更多