2014-10-27 48 views
1

我是新來的RabbitMQ,我一直努力遵循的RabbitMQ的tutorial的RabbitMQ - RabbitMQ的用戶>無連接可以作出,因爲目標機器積極地拒絕它

我複製的代碼send.phpreceive.php,但是當我運行send.phpreceive.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(); 

?> 

有人可以幫我解決這個問題嗎? 在此先感謝

+0

您測試了端口5672是否已被使用嗎? – lcsvcn 2014-10-27 14:59:07

+0

我測試了它,下面這個答案: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

+0

是的,的確,這個港口是有效的。看看我發佈的答案,它可能會幫助你找到錯誤的原因。 – lcsvcn 2014-10-27 17:51:24

回答

0

搜索Error Connecting to server(10061)我發現this

WSAECONNREFUSED (10061)

10061 is a Connection Refused error sent to you by the server. You could not make a connection because the target computer actively refused it. The most common cause is an incorrectly configured server, full server, or incorrect Port specified by the client.

網站上面鏈接中包含有關該錯誤以及可能的原因列表的詳細信息,這可能導致你的解決方案。

相關問題