6
votes

In the context of MQTT and pub/sub, let's assume my embedded micro-controller IOT device has a significant number of variables (i.e., various sensors, values, settings, outputs, etc) which can be mapped to "topics".

Is it really necessary to publish (to a broker) on topics if there are no subscribers for the topics?
I'd like to think I have a fairly decent grasp of MQTT, but as I thought through the implementation for this device, this question jumped out at me. It would not be trivial for this device to always publish on all topics.

Typically in this case, a subscriber will be interested in a small subset of topics, not all. It seems very unnecessary to publish on ALL topics if only a small subset are being subscribed to. Why not only publish on topics being subscribed to?

MQTT subscriber clients typically connect to a broker, then send their subscribe message to the broker. I don't see a mechanism by which subscribers can indicate to publishers what topics they are interested in, thereby allowing publishers to only publish on the necessary topics.

Am I misunderstanding a nuance of MQTT, or more generally, pub/sub?

1

1 Answers

11
votes

Publishers have no idea how many Subscribers there are to any topic.

Part of the point of a pub/sub architecture is to totally decouple the Publishers from the Subscribers, this is all handled by the broker. Yes this can lead to things being published that nobody is listening to but it simplifies the Publisher.

Also when using things like retained topics and persistent sessions, just because the Subscriber is not currently connected it doesn't mean the messages won't be delivered later