繁体   English   中英

Mosquitto 坚持作为 MQTT 转发代理

[英]Mosquitto with persitence as MQTT Forwarding Broker

我们希望在多个 OpenWRT 网关上使用 Mosquitto MQTT 作为消息代理,以将“本地”匿名 MQTT 发布转发到具有授权的中央 RabbitMQ/MQTT 集群。

我们的问题:

Mosquitto 在重新启动时不可靠地转发排队的消息(持久性不起作用)

运行蚊子版本:1.4.15

当前配置

这是最后一次测试的配置:

port 1883
persistence true
persistence_file /mosquitto.db
persistence_location /etc/mosquitto

autosave_interval 1
autosave_on_changes true

allow_anonymous true

connection iotcluster
address ip:1883

notifications false
keepalive_interval 300
restart_timeout 30
start_type automatic

clientid rabbitmqtt
username user
password password

topic mqtt out 2
try_private true

只要所有系统运行并在线 - 一切都按预期工作 - 任何通过以下方式在本地发布的消息:

mosquitto_pub -h localhost -p 1883 -t mqtt -m "Test-Bridge-Online"

将被转发并发布到 RabbitMQTT。

连接丢失

当我们产生连接丢失(例如断开电缆)并重新建立该连接时,在此期间收到的消息不会自动从 Mosquitto 转发到 RabbitMQTT

但是 - 在发送新的发布消息时 - Mosquitto 也会发送排队的消息???

蚊子重启

如果我们在连接丢失期间重新启动 Mosquitto,排队的消息都会丢失 - 没有 PERSISTINACE 选项工作这么久。

请帮忙

我们尝试了autosave_intervalQoS 0/1/2other option combination的不同选项 - 但无论如何 - 在重新启动 Mosquitto 时 - 所有消息都丢失 - 以任何方式都没有持久性

在运行 mosquitto 1.6.10 版的更新后仍然没有成功。

我可以找出主要问题 - 搜索时数据库没有保存:

persistence true
persistence_file /mosquitto.db
persistence_location /etc/mosquitto

autosave_interval 1
autosave_on_changes true

不知道为什么,但无法通过上述设置调用数据库保存。

数据库保存在 SIG-EXIT 上,但在推送新消息时不保存。

所以我将设置更改为:

persistence true
persistence_file /mosquitto.db
persistence_location /etc/mosquitto

autosave_interval 300
autosave_on_changes false

并在推送消息后调用保存数据库的请求:

# publish a new message
mosquitto_pub -h localhost -p 1883 -t mqtt -m "Test Offline 100" -q 1
# send signal to save database
killall -SIGUSR1 mosquitto

使用此功能时 - 所有类型的消息在连接的 state 中排队并被传递。

这是最终的配置:

user mosquitto
port 1883

allow_anonymous true
queue_qos0_messages true

persistence true
persistence_file mosquitto.db
persistence_location /etc/mosquitto/
autosave_interval 300
autosave_on_changes false

connection ConName
address remote-ip:1883
bridge_protocol_version mqttv31
clientid ClientName
username user
password password
cleansession false
try_private false
retain_available false

start_type automatic
restart_timeout 60
keepalive_interval 120

notifications true
notifications_local_only true
notification_topic mqtt

topic mqtt out 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM