Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 349
Rahul Prasad Avatar asked Sep 14 '15 19:09

Rahul Prasad


People also ask

Does WhatsApp use MQTT?

The Python script will have WhatsApp API and MQTT library to communicate with both protocols. The script can send and receive messages on WhatsApp and MQTT.

Does messenger use MQTT?

Facebook uses MQTT for Messenger Chats. Each "Chat" has a generated Topic, and all members in the Chat subscribe and Publish to that generated Topic. The MQTT Messenger Broker infrastructure is made up of "many" different Brokers, and a "Topic Director" steers the Chat MQTT packets to the Broker handling that chat.

Is MQTT good for chat?

There's no denying that MQTT can be the best option for your chat app development too. It requires little implementation efforts and is the most ideal for machine-to-machine communication. It also allows efficient transmission of data and is a good choice for networks that experience different levels of latency.

What uses MQTT for online chat?

Major corporations that use MQTT protocol include Amazon and Facebook. This protocol manages a connection between the publishers and subscribers and the types of connection use various types of communications such as server-to-server, machine-to-machine and server-to-machine.


1 Answers

  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
like image 138
hardillb Avatar answered Sep 24 '22 18:09

hardillb