RabbitMQ, AMQP, MQTT & Rest of the world
Hey folks, welcome back. Hope you all are doing well. Then why wasting time ! Lets move to the tutorial.
Today I am going to write on Message Queue. Very simple nah ? Huh lets dive.
These days we are developing smart applications to make lives easier. There are lots of tech giants with lots of tech engineers fighting to solve problems. There are Google, Facebook, Pathao, Uber, Grab, AirBnB and so on….
A common task we developers do is send notifications or requests to process tasks between applications. One of the solution to do it could be using Message Queue.
RabbitMQ : RabbitMQ is a message queueing hybrid broker. Hybrid is that sense it has support for different protocols like AMQP, MQTT, WebSocket etc.
AMQP ( Advanced Message Queueing Protocol ) : is an open standard application layer protocol for message-oriented middleware. The defining features of AMQP are message orientation, queuing, routing, reliability and security. [ Ref : Wiki ]
MQTT ( Message Queue Telemetry Transport ) : is an ISO standard (ISO/IEC PRF 20922) publish-subscribe-based messaging protocol. It works on top of the TCP/IP protocol. It is designed for connections with remote locations where a “small code footprint” is required or the network bandwidth is limited. The publish-subscribe messaging pattern requires a message broker. Facebook uses MQTT protocol for their messaging engine ( Messenger ). [ Ref : Wiki ]
Lets consider the above scenario. B is subscribed to Topic 1, A is publishing something to Topic 1. And broker is routing message from A to B using topic. Simply this is what broker do and the protocol works.
Now you may ask WTF are so many protocols if all of them are same ?
Ok, all of them are not same. There is small difference with big impact.
MQTT is designed to be used on lightweight devices like Mobile devices, Embedded systems where bandwidth is costly and minimum overhead required. It uses a 2 byte fixed header to control everything and exchange data as byte stream. MQTT is being used widely in IOT.
AMQP is designed with more advanced features and has more overhead than MQTT.
For this reason AMQP is not preferred for lightweight devices like mobile, where MQTT can be used in anywhere.
But in real world application development we may need AMQP like reliable message queue and also has lightweight devices to work with. Here is the point where RabbitMQ comes in. RabbitMQ has the flexibility to use both protocol AMQP & MQTT together.
So the idea is when you are on mobile device use MQTT protocol to connect to RabbitMQ broker. As MQTT protocol is very lightweight and works smoothly with low bandwidth. And for server side communication you can use AMQP or MQTT which one you prefer. Both protocol uses stateful TCP connection for communication. Also has support for WebSocket. RabbitMQ binds MQTT topic to AMQP topic with amq.topic exchange.