MQTT (Message Queue Telemetry Transport) is a lightweight messaging protocol specially designed for IOT by IBM. MQTT works on Publish-Subscribe Model.
Facebook & WhatsApp uses MQTT for their messaging engine.
Well, In the tutorial I am going to show how you can implement a push notification service using MQTT. I am not going to implement complete service but a prototype on how it can be.
Tools will used,
- EMQ (MQTT Broker)
- MongoDB (To store user's information)
- Admin Dashboard (To publish notification)
- Android App (Client)
- Eclipse Paho MQTT client (Android, JavaScript)
Its the big picture, how components in the system are interacting with each other.
The idea is user will connect to mqtt broker, broker will authenticate them with data in mongodb.
Assume a user as system admin who will publish notifications & other users will be subscribed to receive these notifications. Suppose, [email protected] is a user, after authentication with the email address the user will be subscribed to the topic([email protected]) and then from admin dashboard if you publish a message on topic [email protected] the user will receive it. Thats all.
MongoDB Document Schema,
{
"user_email": "email address of user",
"user_password": "password of user",
"type": "admin/user"
}
Assume this is the admin dashboard,
There are 3 buttons. One to Logout, One is to Add User and another to Send Push notifications.
In screen the push notification view is visible. Admin dashboard is connected to MQTT broker via Websocket. User Email Address is the topic where message is going to be published. When clicked on Send it will publish the message using Websocket.
Now if the respective email address is connected & subscribed to respective topic then the client will receive the message.
Note : This is just a prototype for educational purpose not production ready. To use it in production system you have to implement security & other tuning where needed.