我用rabbitMq和videlalvaro / php-amqplib php客户端实现了一个简单的消息服务。但是当我发送两条消息时,我的接收器丢失了一条。任何想法会发生什么?使用的代码如下。
send.php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
$connection = new AMQPConnection('127.0.0.1', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
for ($i=0; $i < 10; $i++) {
$text = "SEND MESSAGE ".$i;
$msg = new AMQPMessage($text);
$channel->basic_publish($msg, '', 'hello');
echo " [x] SEND MESSAGE ".$i."\n";
}
$channel->close();
$connection->close();
receiver.php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPConnection;
$connection = new AMQPConnection('127.0.0.1', 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();
send.php打印回复
[x]发送消息0
[x]发送消息1
[x]发送消息2
[x]发送消息3
[x]发送消息4
[x]发送消息5
[x]发送消息6
[x]发送消息7
[x]发送消息8
[x]发送消息9
receiver.php打印回复
[x]收到:发送消息1
[x]收到:发送消息3
[x]收到:发送消息5
[x]收到:发送消息7
[x]收到:发送消息9
答案 0 :(得分:0)
遇到同样的麻烦并且花费了很多时间来寻找解决方案。最后,安装Rabbit Server的磁盘上存在可用空间不足。它说“50mb水印”,但不知何故麻烦从1GB的可用空间开始。消息正在某个地方。
尝试红色服务器日志,也许你会找到提示。