Assuming you have basic idea about what is MQTT protocol. If you don’t know what is MQTT protocol, please visit the link.
MQTT Communication happens in four Ways:
1)Single Publisher, Single Subscriber
2)Single Publisher, Multiple Subscriber
3)Multiple Publisher, Single Subscriber
4)Multiple Publisher, Multiple Subscriber
A Publisher can be python script, ESP8266 NodeMCU, Command prompt of computer, linux terminal , Java Program etc. A Subscriber can be python script, ESP8266 NodeMCU, Command prompt of computer, linux terminal , Java Program etc
In Single Publisher, Single Subscriber communication, there is one publisher and one subscriber. Publisher is Publishing data or message “bytesofgigabytes.com” to the broker on the topic test. As Subscriber is subscribed to the same topic test , the message received by Subscriber is same as message published by Publisher. If Subscriber is subscribed with different topic Demo then Subscriber won’t be able to receive data published by publisher on topic test . Single Publisher, Single Subscriber communication is shown above figure.
In Single Publisher, Multiple Subscriber communication, There is one Publisher and there are multiple Subscribers. Multiple subscribers may or may not subscribe the same topic simultaneously. Subscription of topic depends on from which publisher subscriber wants to receive data. Default maximum number of subscribers can connect to broker are around 1023. In above figure Publisher is publishing data or message “bytesofgigabytes.com” on topic test and Subscribers who all are having subscribed topic test will receive the data “bytesofgigabytes.com” , as such Subscribers are Subscriber 1 , Subscriber 2 , Subscriber 3 . But if you observe in above figure, Subscriber 4 hasn’t received data because Subscriber 4 is subscribed to different topic Demo and there is no publisher for that topic. Maximum number of default Subscribers are 1023, Here for understanding 4 Subscribers have taken.
In Multiple Publisher, Single Subscriber communication, there are multiple Publishers and there is Single Subscriber. Multiple publishers may or may not publish data to same topic simultaneously. In above figure different Publishers are publishing different data on same topic test and there is only one subscriber, who have subscribed the topic test. As the Subscriber is subscribed to topic test, it will receive data from all the publishers who all are publishing the data on topic test. If you observe in above figure , Publisher 4 is publishing data “Vocabulary” on different topic Demo and Subscriber have Subscribed different topic test , Because of this Subscriber is able to receive data from only Publisher 1 , Publisher 2 , Publisher 3 and not from Publisher 4. Maximum number of default Publishers are 1023. Publisher can Publish data on whichever topic they want. No need to have same topic to all publishers.
In Multiple Publisher, Multiple Subscriber Communication, there are multiple Publishers as well as Multiple Subscribers. All Publishers can publish data to same or different topics simultaneously .All Subscribers can subscribe to same or different topics simultaneously . In above figure for understanding purpose 4 subscribers and 4 publishers have considered . Publisher 1 and Publisher 2 are publishing different data “bytesofgigabytes.com” & “google” respectively on topic test. As Subscriber 1 and Subscriber 2 have Subscribed same topic test, both will receive the data publish by Publisher 1 and Publisher 2. But Subscriber 3 and Subscriber 4 won’t receive the data publish by Publisher 1 and Publisher 2 as Subscriber 3 & Subscriber 4 , subscribed topic is different from Publisher 1 & publisher 2 topic. Subscriber 3 and Subscriber 4 will receive the data publish by Publisher 3 and Publisher 4 as they have same topic Demo . Subscriber 1 and Subscriber 2 won’t receive the data publish by Publisher 3 and Publisher 4 as Subscriber 1 & Subscriber 2 , subscribed topic is different from Publisher 3 & publisher 4 topic.