【发布时间】: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 还是有其他更好的方法?
【问题讨论】: