RabbitMQ - rabbitmq-users › 由于目标机器主动拒绝,无法建立连接

Jan*_*368 5 php connection rabbitmq

我是 RabbitMQ 的新手,我一直在尝试学习RabbitMQ的教程

我已经复制了send.phpand的代码receive.php,但是当我运行send.phpandreceive.php脚本时,出现以下错误:

Error Connecting to server(10061).: No connection could be made because the target machine actively refused it

我已禁用防火墙和所有防病毒程序,但仍然出现相同的错误。

send.php和receive.php的代码:


发送.php

<?php

    require_once __DIR__ . '/vendor/autoload.php';
    use PhpAmqpLib\Connection\AMQPConnection;
    use PhpAmqpLib\Message\AMQPMessage;

    $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
    $channel = $connection->channel();


    $channel->queue_declare('hello', false, false, false, false);

    $msg = new AMQPMessage('Hello World!');
    $channel->basic_publish($msg, '', 'hello');

    echo " [x] Sent 'Hello World!'\n";

    $channel->close();
    $connection->close();

?>
Run Code Online (Sandbox Code Playgroud)

接收.php

<?php

    require_once __DIR__ . '/vendor/autoload.php';
    use PhpAmqpLib\Connection\AMQPConnection;

    $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
    $channel = $connection->channel();


    $channel->queue_declare('hello', false, false, false, false);

    echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";

    $callback = function($msg) {
         echo " [x] Received ", $msg->body, "\n";
    };

    $channel->basic_consume('hello', '', false, true, false, false, $callback);

    while(count($channel->callbacks)) {
        $channel->wait();
    }

    $channel->close();
    $connection->close();

?>
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个问题吗?提前致谢