mqttinstant-messagingmessenger

How to I implement whatsapp type messenger using MQTT?


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.


Solution

    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