首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mosquitto作为MQTT转发代理

Mosquitto作为MQTT转发代理
EN

Stack Overflow用户
提问于 2021-05-21 18:05:29
回答 1查看 245关注 0票数 0

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

我们的问题:

Mosquitto在重启时不能可靠地转发队列中的消息(持久性不起作用)

运行蚊子版本: 1.4.15

当前配置

这是最后测试的配置:

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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选项-但无论如何-重启蚊子-所有消息都会丢失-不会以任何方式持久

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-22 22:00:34

在运行了到蚊子1.6.10版本的更新后,仍然没有成功。

我可以找出主要的问题-数据库在查看时没有保存:

代码语言:javascript
复制
persistence true
persistence_file /mosquitto.db
persistence_location /etc/mosquitto

autosave_interval 1
autosave_on_changes true

不确定原因,但无法通过上述设置调用数据库的保存。

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

因此,我将设置更改为:

代码语言:javascript
复制
persistence true
persistence_file /mosquitto.db
persistence_location /etc/mosquitto

autosave_interval 300
autosave_on_changes false

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

代码语言:javascript
复制
# 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

当使用这个时-所有类型的消息都在连接的状态中排队并被传递。

这是最终的配置:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67634784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档