AMQPRuntimeException:读取数据时出错.收到0而不是预期的7个字节

M D*_*D P 4 php amqp rabbitmq

它工作,但现在它不再工作了!

我正在使用php-amqplib和RabbitMQ.

当我尝试创建新的AMQP连接时:

$connection = new AMQPConnection('localhost', 5672, 'username', 'password');
Run Code Online (Sandbox Code Playgroud)

导致此错误的库中的代码是:

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;
}
Run Code Online (Sandbox Code Playgroud)

当我把它放在异常之前:

die($res." :".$n);
Run Code Online (Sandbox Code Playgroud)

结果是:

Ï :7 :7
Run Code Online (Sandbox Code Playgroud)

它被调用两次,在第一次调用$ res是两个空字符然后"Ï"

在第二次调用它只是null.

哦,我手动删除了rabbitmq数据库的mnesia文件夹中的文件一次,我不知道是否会导致问题,但RabbitMQ管理是一个运行在端口15672上的基于Web的应用程序工作正常.

M D*_*D P 9

我找到了解决方案.

我使用的用户无法访问vhost,因此在RabbitMQ Management中,我转到了admin选项卡并单击了用户名,然后单击了"set permission"按钮.


hse*_*rge 5

如果端口号错误,您也会收到此错误。我错误地使用了管理端口 15672 而不是服务器端口 5672,并且遇到了同样的错误。

因此,如果用户权限调整不起作用,请检查连接参数。