5

I want to implement a messenger just like whatsapp using MQTT protocol. What tutorials should I read ?

I am confused about few things:

  1. How should I implement topic structure for messaging ? (Currently I am using /domainname/phonenumber/ (If phone A whats to send message to phone B, it will publish a message to /domainname/B/)
  2. If client B goes offline and comes online after some time, how will it receive message sent to him (to topic /domainname/B/) while client was offline ?
  3. How do I implement sent/delivered/read acknowledgement ?

I understand that these are very basic questions, but unfortunately I could not find any resources which guides though initial steps.

Conclusion:
After talking to people who have already implemented large scale messenger deployment in MQTT, I concluded that MQTT should just be used an protocol. Pub/Sub is good for beginning but you should have a layer of your own business logic for flexibility and performance. You can however implement most of the basic messenger requirement using pub/sub tree, but you will be limited to it and it will become difficult to extend later.

Rahul Prasad
  • 8,074
  • 8
  • 43
  • 49
  • In case you got the solution, can you please share ? – Manish Kumar Jan 27 '16 at 05:37
  • @Toomuchtolearn Yup, After taking to people who have already implemented large scale messenger deployment in MQTT, I concluded that MQTT should just be used an protocol. Pub/Sub is good for beginning but you should have a layer of your own business logic for flexibility and performance. You can however implement it using pub/sub tree, but you will be limited to it and it will become difficult to extend later. – Rahul Prasad Jan 28 '16 at 13:13
  • let say for whatsapp type app we have too choice 'XMPP` and `MQTT` . i have hearead that MQTT is very light so battery friendly but XMPP is too heavy compared to MQTT. SO wht is you take on these two and what will you go with? – Manish Kumar Jan 29 '16 at 00:54
  • ..and also what kind of limitation are u talking about ? does MQTT work well with audio video streaming ? – Manish Kumar Jan 29 '16 at 05:02

3 Answers3

5
  1. Topic structure looks fine, but probably should have a ACL in place so clients can only subscribe to their own topics.
  2. As long as you don't set the "cleansession" option to true then the broker should store and forward any messages sent to a topic the client was subscribed to before it disconnected
  3. MQTT contains no support for Sent/delivered/read notifications, you will need to implement this yourself, easiest way will be a to have 2 topics per client, one to receive messages on and one to receive notifications on. Each message should have a id number that can be used in the notifications sent back to the original sender
hardillb
  • 54,545
  • 11
  • 67
  • 105
  • I was testing client using mqtt://test.mosquitto.org for point 2. Does it have "cleansession" enabled ? Because it did not returned messages when subscriber comes online. – Rahul Prasad Sep 15 '15 at 07:54
  • 1
    cleansession is a client option not a broker option. It also relies on the client id being the same. Read this for a better explanation http://www.hivemq.com/mqtt-essentials-part-7-persistent-session-queuing-messages/ – hardillb Sep 15 '15 at 08:06
0

I have implemented fundamental mqtt functions by a react native client, it's able to send/receives messages use standard mqtt server, and all code has been integrated into the rnset project, which is a github react native project.
You can check it out from here .
After Running the rnset you may check the demo from rnset->功能(demos)->MQTTChat

Til
  • 5,150
  • 13
  • 26
  • 34
0

rnset/qmtt/mqttbox; in fact the rnset/mqtt demo is running on my iphon7p by 4G, and mqttbox is running on my Mac, the message can be received simultaneously.

UI IPhone/Mac:

UI IPhone/Mac

kenlukas
  • 3,616
  • 9
  • 25
  • 36