我是新來的RabbitMQ,我一直努力遵循的RabbitMQ的tutorial。的RabbitMQ - RabbitMQ的用戶>無連接可以作出,因爲目標機器積極地拒絕它
我複製的代碼send.php
和receive.php
,但是當我運行send.php
和receive.php
腳本,我得到以下錯誤:
Error Connecting to server(10061).: No connection could be made because the target machine actively refused it
我停用了防火牆和我所有的防病毒程序,但我仍然得到相同的錯誤。
send.php和receive.php的代碼:
send.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();
?>
receive.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();
?>
有人可以幫我解決這個問題嗎? 在此先感謝
您測試了端口5672是否已被使用嗎? – lcsvcn 2014-10-27 14:59:07
我測試了它,下面這個答案:http://stackoverflow.com/questions/273159/how-to-determine-if-a-port-is-open-on-a-windows-server。 所以當我執行命令「telnet localhost 5672」時,我無法建立連接。所以我認爲該端口仍然可用? 我也嘗試更改de-php文件中的portnumber,但仍然像以前一樣得到相同的錯誤。 – Jan368 2014-10-27 15:14:07
是的,的確,這個港口是有效的。看看我發佈的答案,它可能會幫助你找到錯誤的原因。 – lcsvcn 2014-10-27 17:51:24