communication runtime_error ai_generated true

MQTT publish failed: no subscribers matched topic filter

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

Also available as: JSON · Markdown · 中文
75%Fix Rate
82%Confidence
1Evidence
2024-03-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Mosquitto 2.0.15 active — — —
Paho MQTT 1.6.1 active — — —
EMQX 5.0.0 active — — —

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

  1. 80% success 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.
    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. 75% success 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.
    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. 85% success 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.
    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. 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.

Dead Ends

Common approaches that don't work:

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

    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% fail

    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% fail

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