AMQPRuntimeException: Error reading data. Received 0 instead of expected 7 bytes

浪尽此生 提交于 2019-12-10 17:53:46

问题


It was working, but now it's not working anymore!

I'm using php-amqplib and RabbitMQ.

when I'm trying to create a new AMQP connection:

$connection = new AMQPConnection('localhost', 5672, 'username', 'password');

The code inside the library that is causing this error is:

public function read($n)
{
    $res = '';
    $read = 0;

    while ($read < $n && !feof($this->sock) &&
        (false !== ($buf = fread($this->sock, $n - $read)))) {

        if ($buf === '') {
            continue;
        }

        $read += strlen($buf);
        $res .= $buf;
    }

    if (strlen($res)!=$n) {
        throw new AMQPRuntimeException("Error reading data. Received " .
            strlen($res) . " instead of expected $n bytes");
    }

    return $res;
}

When I put this just before the exception:

die($res." :".$n);

the result is:

Ï :7 :7

it is called twice, in first call $res is two null characters then "Ï"

and in second call it's just null.

oh and I deleted files inside mnesia folder of rabbitmq database manually once, I don't know if that caused the problem, but the RabbitMQ Management which is a web based app running on port 15672 is working fine.


回答1:


I found the solution.

the user I was using didn't have access to the vhost, so in RabbitMQ Management I went to the admin tab and clicked on the username, and clicked on "set permission" button.




回答2:


You'll get this error also if port number is wrong. I was using management port 15672 instead of server port 5672 by mistake and was getting this same error.

So if user permission tweaking doesn't work then check connection parameter.




回答3:


I know this has been answered already, but here's another possible cause:

The default "guest" user can only connect via localhost, by default. https://www.rabbitmq.com/access-control.html

I got this 'received 0' error when trying to connect remotely for the first time after testing successfully locally. Setting up a different user solved it for me.

rabbitmqctl add_user newuser <PASSWORD>
rabbitmqctl set_permissions -p / newuser ".*" ".*" ".*"

This and many other potential answers are also on github here



来源:https://stackoverflow.com/questions/25226607/amqpruntimeexception-error-reading-data-received-0-instead-of-expected-7-bytes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!