8
votes

Recently I had read an iot article http://www.eclipse.org/community/eclipse_newsletter/2014/february/article2.php In this he is saying that, by mqtt protocol clients can communicate both in one to many and many to one ways. In the mqtt spec itself mentioning about the one to many but I had little confusion in many to one. What I understood is, many clients are publishing on same topic and there is only one subscriber for these different publishers.Then how the subscriber(user) should identify message belongs to which publisher? Another doubt, if two publishers used the same topic to publish their data without knowing each other, because of every client is connected to the internet, the subscriber will get both the datas. But that is not what the subscriber expected.He wants data from only one publisher. Is there any chance to occur the same scenario in mqtt communication?

2

2 Answers

11
votes

Here are some facts about MQTT that will perhaps help you understand.

  1. A publisher does not "own" a topic. A publisher may choose to publish a message to ANY topic (assuming it is a valid MQTT topic).

  2. Given point 1 above, any number of publishers may simultaneously publish to the same topic.

  3. A client can choose to subscribe to specific or wildcarded topics to receive information published from any publisher.
  4. A client can be both a publisher and subscriber (it would even be possible for a client to receive its own published message).
  5. The MQTT Broker takes care of managing all relationships between clients. Clients dot not know (or care) which other clients are currently connected to the broker. Publishers and subscribers are completely decoupled although they may communicate using MQTT capabilities (pub/sub).
  6. It is possible that a publisher's message is discarded because no subscribers are currently interested in that message. (e.g.: publisher publishes to topic "topic1". If no subscribers had previously requested a subscription to "topic1", the message will be discarded by the MQTT broker since it has no client to send it to).
  7. A single publisher can publish to multiple clients at once. (e.g.: 10 clients come online and request a subscription to topic "topic1". Another client comes online and publishes to "topic1". All 10 subscribers to "topic1" will receive the message. The publisher simply had to publish one message to the MQTT broker, the MQTT broker is responsible for relaying the message to all 10 subscribers).

Hopefully these tidbits of information will help you understand, please let me know if I anything is still unclear.

0
votes

"It is possible that a publisher's message is discarded because no subscribers are currently interested in that message. (e.g.: publisher publishes to topic "topic1". If no subscribers had previously requested a subscription to "topic1", the message will be discarded by the MQTT broker since it has no client to send it to)" Is it applicable even by publishing with retain flag set? because I understood that if retain flag is set the broker will store the session of that particular topic and whenever a subscriber is available to that same topic.The broker will handover those messages to the subscribed client.