Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

rabbitmq

amqp

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.

like image 850
M D P Avatar asked Dec 07 '22 00:12

M D P


1 Answers

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.

like image 119
M D P Avatar answered Feb 17 '23 01:02

M D P