communication runtime_error ai_generated true

MQTT 发布失败:无订阅者匹配主题过滤器

MQTT publish failed: no subscribers matched topic filter

ID: communication/mqtt-publish-failed-no-subscribers

其他格式: JSON · Markdown 中文 · English
75%修复率
82%置信度
1证据数
2024-03-22首次发现

版本兼容性

版本状态引入弃用备注
Mosquitto 2.0.15 active — — —
Paho MQTT 1.6.1 active — — —
EMQX 5.0.0 active — — —

根因分析

MQTT 代理丢弃发布的消息,因为没有活动订阅者订阅该主题或任何匹配的通配符主题。

English

The MQTT broker discards the published message because no active subscribers are subscribed to the topic or any wildcard matching it.

generic

官方文档

https://mqtt.org/mqtt-specification/

解决方案

  1. Ensure at least one subscriber is connected before publishing: In the publisher code, implement a callback to wait for a subscriber presence notification or use a separate health-check topic. For example, in Eclipse Paho Python client, subscribe to '$SYS/broker/clients/connected' to monitor.
  2. Use MQTT 5.0 subscription identifiers to track active subscribers: Set `SubscriptionIdentifier` in the publish packet and check broker response for 'no matching subscribers' reason code.
  3. Configure the broker to store undelivered messages with a queue for offline subscribers: In Mosquitto, set `persistence true` and use `max_queued_messages 1000` with a clean session false for the subscriber.

无效尝试

常见但无效的做法:

  1. Publish with QoS 2 to guarantee delivery even without subscribers 85% 失败

    QoS levels do not create subscribers; the broker still drops the message if no one is subscribed.

  2. Enable broker's retained messages feature to store the last message 70% 失败

    Retained messages only store the last message per topic; they don't affect delivery of new messages to non-existent subscribers.

  3. Set the 'clean session' flag to false on the publisher 90% 失败

    The clean session flag applies to client session state, not subscriber existence; it doesn't create subscribers.