Closed addls closed 3 years ago
recv
失败了?打印对应的errCode
和errMsg
errCode: 60 errMsg: Operation timed out
用dev-master试下,这里改过一次没发版 https://github.com/simple-swoole/simps/blob/master/src/Client/MQTTClient.php#L143
是使用的dev-master,如图。strlen换了下位置,否则会报错: Whoops\Exception\ErrorException : Uncaught TypeError: strlen() expects parameter 1 to be string, bool given。
好吧,我下午看看
你swoole什么版本,客户端的配置代码也一起发下
Swoole: 4.5.4
Simps: 1.0.4
Broker是rabbitMQ 3.8.7
$config = [
'host' => config('servers.rabbitmq.host'),
'port' => config('servers.rabbitmq.port'),
'time_out' => config('servers.rabbitmq.time_out'),
'username' => config('servers.rabbitmq.username'),
'password' => config('servers.rabbitmq.password'),
'client_id' => config('servers.rabbitmq.client_id'),
'keepalive' => 10,
];
try {
\Co\run(function () use ($config) {
$client = new MQTTClient($config);
while (!$client->connect(true)) {
\Swoole\Coroutine::sleep(3);
$client->connect(true);
}
$topics['v1/devices/me/telemetry'] = 0;
$timeSincePing = time();
$client->subscribe($topics);
while (true) {
$buffer = $client->recv();
Log::info('TelemetrySubscribe', [$buffer]);
if ($buffer && $buffer !== true) {
$timeSincePing = time();
}
if (isset($config['keepalive']) && $timeSincePing < (time() - $config['keepalive'])) {
$buffer = $client->ping();
if ($buffer) {
echo '发送心跳包成功' . PHP_EOL;
$timeSincePing = time();
} else {
$client->close();
break;
}
}
}
});
} catch (\Exception $e) {
Log::error('onMqPublish', [
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
}
RABBITMQ_HOST=10.168.2.102
RABBITMQ_PORT=1883
RABBITMQ_TIMEOUT=5
RABBITMQ_USERNAME=test
RABBITMQ_PASSWORD=test
RABBITMQ_CLIENT_ID=TP1
用master还能复现问题吗?这里应该直接会异常掉
是的,你那边不能重现?
只是超时,recv默认用的connect的超时时间,你调大些应该就可以了
我晚上试试
测试了下,发现问题在于,当发送消息的数量接近100条时(使用MQTTBox连续点击publish),subscribe程序就会卡住收不到消息了。
publish了什么信息,qos几?sub有返回响应吗?
对端的问题,你可以用php代码实现client和server进行测试是否复现,复现了把代码贴出来。
刚订阅时能正常收到消息,运行几十分钟后就收不到消息了: https://simps.io/#/zh-cn/mqtt/client?id=%e8%ae%a2%e9%98%85