它工作,但现在它不再工作了!
我正在使用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的应用程序工作正常.
我找到了解决方案.
我使用的用户无法访问vhost,因此在RabbitMQ Management中,我转到了admin选项卡并单击了用户名,然后单击了"set permission"按钮.