简体   繁体   English

Mosquitto 坚持作为 MQTT 转发代理

[英]Mosquitto with persitence as MQTT Forwarding Broker

We want to use Mosquitto MQTT as Message Broker on a number of OpenWRT gateways to forward "local" anonymous MQTT publications to a central RabbitMQ/MQTT cluster with authorization.我们希望在多个 OpenWRT 网关上使用 Mosquitto MQTT 作为消息代理,以将“本地”匿名 MQTT 发布转发到具有授权的中央 RabbitMQ/MQTT 集群。

Our Problem:我们的问题:

Mosquitto does not reliable forward queued messages when restarted (persistance does not work) Mosquitto 在重新启动时不可靠地转发排队的消息(持久性不起作用)

Running mosquitto version: 1.4.15运行蚊子版本:1.4.15

current config当前配置

This is the last tested config:这是最后一次测试的配置:

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

As long as all systems running and online - everything works as expected - any message published locally via:只要所有系统运行并在线 - 一切都按预期工作 - 任何通过以下方式在本地发布的消息:

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

will be forwarded and published to the RabbitMQTT.将被转发并发布到 RabbitMQTT。

connection lost连接丢失

When we produce a connection lost (eg disconnect cable) and re-establish that connection, the messages received in the meantime won't be automatically forward from Mosquitto to RabbitMQTT当我们产生连接丢失(例如断开电缆)并重新建立该连接时,在此期间收到的消息不会自动从 Mosquitto 转发到 RabbitMQTT

BUT - when sending a new publish message in addtion - Mosquitto will send out also the queued messages???但是 - 在发送新的发布消息时 - Mosquitto 也会发送排队的消息???

Mosquitto restart蚊子重启

If we restart the Mosquitto during the connection lost, the queued messages are all lost - NO PERSISTINACE options worked so long.如果我们在连接丢失期间重新启动 Mosquitto,排队的消息都会丢失 - 没有 PERSISTINACE 选项工作这么久。

Please help请帮忙

We tried different options of autosave_interval , QoS 0/1/2 ond other option combination - but in anyway - on restart Mosquitto - all messages are lost - NO PERSISTANCE in any way我们尝试了autosave_intervalQoS 0/1/2other option combination的不同选项 - 但无论如何 - 在重新启动 Mosquitto 时 - 所有消息都丢失 - 以任何方式都没有持久性

After running an update to mosquitto version 1.6.10 still no success.在运行 mosquitto 1.6.10 版的更新后仍然没有成功。

I could isolate the main problem - the database did not save when seetings:我可以找出主要问题 - 搜索时数据库没有保存:

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

autosave_interval 1
autosave_on_changes true

Not sure why but could not manage to invoke a save of database by the above settings.不知道为什么,但无法通过上述设置调用数据库保存。

The database save on SIG-EXIT but not when pushing new message.数据库保存在 SIG-EXIT 上,但在推送新消息时不保存。

So I changed the settings to:所以我将设置更改为:

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

autosave_interval 300
autosave_on_changes false

and invoke a request to save the database after pushing the message:并在推送消息后调用保存数据库的请求:

# 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

When using this - all kind of messages where queued in an state of the connection and get delivered.使用此功能时 - 所有类型的消息在连接的 state 中排队并被传递。

That's the final configuration:这是最终的配置:

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