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?
Q- Can I get list of all topics on a broker? A- Not unless you subscribe to all topics and scan them.
In MQTT the process of sending messages is called publishing, and to receive messages an MQTT client must subscribe to an MQTT topic.
MQTT is the standard protocol for messaging and data exchange for the Internet of Things. The protocol uses a publish/subscribe architecture. The technology provides a scalable and cost-effective way to connect devices over the Internet.
MQTT Publish/Subscribe PatternIn the client-sever model, a client communicates directly with an endpoint. The pub/sub model decouples the client that sends a message (the publisher) from the client or clients that receive the messages (the subscribers). The publishers and subscribers never contact each other directly.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With