Search code examples
mqttmosquitto

Is there a way of determining what MQTT topics have been subscribed to?


I have a microcontroller that has the potential to publish 1,000's of different topics at a relatively high rate.

I also have a raspberryPi that is running mosquitto as well as a separate MQTT client. The MQTT client on my pi will dynamically subscribe and unsubscribe to various topics published by the MCU. The Pi will only be subscribed to ~10 topics at any given point in time. I am also planning on adding additional clients that will dynamically subscribe/unsubscribe to various topics.

For the sake of keeping network traffic to a minimum, I would like to only publish to topics if they have been subscribed to. So, is there some way of querying mosquitto to identify which topics have been subscribed to?


Solution

  • The whole point of a pub/sub architecture is to decouple the consumers from the providers. Your publisher REALLY should NOT care if there is anybody subscribed to a given topic.

    Also with persistent sessions and QOS 1/2 subscriptions it's possible that the broker will be queuing messages for clients that are offline at the time the message is published.

    Just publish all the messages and let the broker deal with it.