发送 MQTT 消息时,第一条消息在 2 秒内到达,后续消息在第一条消息后不到 20 秒内发送,大约在 0.5 秒内到达。
我想加快那些“第一个”消息的速度,并想知道是否有一种方法可以保持线路热,而不会用不必要的保持活动的消息轰炸客户端。
我在几乎没有负载的 Ubuntu 18.04.5 LTS 上运行 Mosquitto 2.0.4 版,它只运行代理并且除了我正在测试的订阅者之外没有其他订阅者。
客户端是通过 3G 网络连接的 Arduino 1400 MKR GSM,它连接到代理,然后在消息接收回调上循环,没有任何其他任务。
mosquitto.conf
pid_file /var/run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
log_timestamp true
log_timestamp_format %Y-%m-%d %H:%M:%S
log_type all
include_dir /etc/mosquitto/conf.d
默认配置文件
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883
protocol mqtt
listener 8883
protocol mqtt
listener 8000
protocol websockets
listener 9001
protocol websockets
listener 8083
protocol websockets
cafile /etc/nginx-sp/ssl/xxx.combined_crt
keyfile /etc/nginx-sp/ssl/xxx.key
certfile /etc/nginx-sp/ssl/xxx.combined_crt
编辑
发布者代码 使用 phpMQTT:
$mqtt = new phpMQTT($server, $port, $client_id);
if ($mqtt->connect(true, NULL, $username, $password)) {
$mqtt->publish($topic, $payload, 0);
$mqtt->close();
return 1;
}