前几条消息在传输到离线的 mqtt 客户端时丢失
Posted
技术标签:
【中文标题】前几条消息在传输到离线的 mqtt 客户端时丢失【英文标题】:The first few messages are lost when transmitted to mqtt clients that were offline 【发布时间】:2021-08-31 03:30:45 【问题描述】:我有使用 paho mqtt 库的 vernemq 服务器和 mqtt 客户端(使用 python 或 C - 无论如何)。订阅者和发布者都使用 Qos2 和 clean_session == False。所以问题是当订阅者离线时,我尝试发送一些消息。其中一些丢失了。仔细研究了参数,发现第一个max_inflight_messages丢失了。我的意思是。在配置文件 vernemq.conf 中,我设置 max_inflight_messages = 20(默认情况下)。然后订阅者下线,我发送21条消息,然后订阅者上线,前20条丢失,21s送达。我用不同数量的消息尝试了很多次 - 结果相同,前 20 条消息丢失,从 21 条开始,下一条消息被接收。当我尝试 max_inflight_messages = 1 时,第一条消息丢失,其他消息被接收。有任何想法吗?我的文件 vernemq.conf:
allow_anonymous = on
allow_register_during_netsplit = off
allow_publish_during_netsplit = off
allow_subscribe_during_netsplit = off
allow_unsubscribe_during_netsplit = off
allow_multiple_sessions = off
coordinate_registrations = on
max_inflight_messages = 20
max_online_messages = 1000
max_offline_messages = 1000
max_message_size = 0
upgrade_outgoing_qos = off
listener.max_connections = 10000
listener.nr_of_acceptors = 10
listener.tcp.default = 0.0.0.0:1883
listener.vmq.clustering = 0.0.0.0:44053
listener.http.default = 0.0.0.0:8888
systree_enabled = on
systree_interval = 20000
graphite_enabled = off
graphite_host = localhost
graphite_port = 2003
graphite_interval = 20000
shared_subscription_policy = prefer_local
plugins.vmq_passwd = off
plugins.vmq_acl = on
plugins.vmq_diversity = off
plugins.vmq_webhooks = off
plugins.vmq_bridge = off
metadata_plugin = vmq_plumtree
vmq_acl.acl_file = ./etc/vmq.acl
vmq_acl.acl_reload_interval = 10
vmq_passwd.password_file = ./etc/vmq.passwd
vmq_passwd.password_reload_interval = 10
vmq_diversity.script_dir = ./share/lua
vmq_diversity.auth_postgres.enabled = off
vmq_diversity.postgres.ssl = off
vmq_diversity.postgres.password_hash_method = crypt
vmq_diversity.auth_cockroachdb.enabled = off
vmq_diversity.cockroachdb.ssl = on
vmq_diversity.cockroachdb.password_hash_method = bcrypt
vmq_diversity.auth_mysql.enabled = off
vmq_diversity.mysql.password_hash_method = password
vmq_diversity.auth_mongodb.enabled = off
vmq_diversity.mongodb.ssl = off
vmq_diversity.auth_redis.enabled = off
vmq_bcrypt.pool_size = 1
log.console = both
log.console.level = debug
log.console.file = ./log/console.log
log.error.file = ./log/error.log
log.syslog = off
log.crash = on
log.crash.file = ./log/crash.log
log.crash.maximum_message_size = 64KB
log.crash.size = 10MB
log.crash.rotation = $D0
log.crash.rotation.keep = 5
nodename = VerneMQ@127.0.0.1
distributed_cookie = vmq
erlang.async_threads = 64
erlang.max_ports = 262144
leveldb.maximum_memory.percent = 70
【问题讨论】:
【参考方案1】:问题出在 paho mqtt 库中。当客户端连接到代理时,他会收到所有消息,但只有在订阅具体主题时才会分配此消息的处理程序。
【讨论】:
以上是关于前几条消息在传输到离线的 mqtt 客户端时丢失的主要内容,如果未能解决你的问题,请参考以下文章