我尝试从php连接到RabbitMQ。 这是我在遵循这些问题后的配置:https://www.rabbitmq.com/ssl.html
/etc/rabbitmq/rabbitmq.config
[
{rabbit, [
{password_hashing_module, rabbit_password_hashing_sha512},
{ssl_listeners, [{"0.0.0.0", 5671}]},
{ssl_options, [{cacertfile,"/var/www/rabbitmq/testca/cacert.pem"},
{certfile,"/var/www/rabbitmq/server/cert.pem"},
{keyfile,"/var/www/rabbitmq/server/key.pem"}
]}
]}
].
使用这个php lib:https://github.com/php-amqplib/php-amqplib
netstat -lpn | grep 5671
tcp 0 0 0.0.0.0:5671 0.0.0.0:* LISTEN 10420/beam.smp
Php测试脚本:
use PhpAmqpLib\Connection\AMQPSSLConnection;
use PhpAmqpLib\Message\AMQPMessage;
define('AMQP_DEBUG', true);
$ssl_options = array(
'cafile' => '/var/www/rabbitmq/testca/cacert.pem',
'certfile' => '/var/www/rabbitmq/client/cert.pem',
'keyfile' => '/var/www/rabbitmq/client/key.pem',
'allow_self_signed' => true,
'verify_peer' => true
);
$connection = new AMQPSSLConnection(
'192.168.1.10',
5671,
'user',
'pass',
'/',
$ssl_options);
$channel = $connection->channel();
我收到此错误:
PHP Fatal error: Uncaught ErrorException: stream_socket_client(): SSL: Handshake timed out in /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:134
StreamIO.php第134行是" $错误号,":
try {
$this->sock = stream_socket_client(
$remote,
$errno,
$errstr,
$this->connection_timeout,
STREAM_CLIENT_CONNECT,
$this->context
);
} catch (\ErrorException $e) {
restore_error_handler();
throw $e;
}
操作系统:Ubuntu 16.04
PHP:7.0.22
执行此脚本时,RabbitMQ日志为空。