Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must a MQTT client publish to topic(s) if there are no subscribers?

Tags:

mqtt

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?

like image 420
Matthew B Avatar asked Sep 07 '15 05:09

Matthew B


People also ask

Can a client subscribe to all the topics available with broker in MQTT?

Q- Can I get list of all topics on a broker? A- Not unless you subscribe to all topics and scan them.

Is MQTT publish subscription?

In MQTT the process of sending messages is called publishing, and to receive messages an MQTT client must subscribe to an MQTT topic.

Is MQTT based on publish subscribe architecture?

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.

How does MQTT publishing work?

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.


1 Answers

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

like image 166
hardillb Avatar answered Jan 04 '23 04:01

hardillb