What is MQTT protocol & its use

So let' start journey towards gets basics about MQTT.


Before understanding MQTT, we should know what basically is publish/subscribe design pattern.The publish/subscribe pattern (also known as pub/sub) provides an alternative to traditional client-server architecture. 


  1. In the client-sever model, a client communicates directly with an endpoint.
  2. The pub/sub model decouples the client that sends a message (the publisher) from the client or clients that receive the messages (the subscribers).
  3. The publishers and subscribers never contact each other directly. In fact, they are not even aware that the other exists. 
  4. The connection between them is handled by a third component (the Broker - eg https://mosquitto.org). The job of the Broker is to filter all incoming messages and distribute them correctly to subscribers.

Now coming back to MQTT -

MQTT is a Client Server publish/subscribe messaging transport protocol.

Being a light weight, open, simple protocol, make it ideal for use in many situations, including constrained environments such as for communication in Machine to Machine (M2M) and Internet of Things (IoT) contexts where a small code footprint is required and/or network bandwidth is at a premium.

- MQTT decouples the publisher from the subscriber, client connections are always handled by a Broker

So let's understand some of the basic components  that make MQTT as a whole communication -

  1. Client - Both publishers and subscribers are MQTT clients.
    An MQTT client is any device (from a micro controller up to a full-fledged server) that runs an MQTT library and connects to an MQTT broker over a network.
    The MQTT client can also be a typical computer running a graphical MQTT client for testing purposes, like MQTT.fx.
    Any device that speaks MQTT over a TCP/IP stack can be called an MQTT client.
    MQTT client libraries are available for almost all programming languages. For example, Android, Arduino, C, C++, C#, Go, iOS, Java, JavaScript, and .NET.
  2. Broker -
    • The Broker is at the core of any publish/subscribe protocol.
    • A Broker can handle up to thousands of concurrently connected MQTT clients.
    • The Broker is responsible for receiving all messages, filtering the messages, determining who is subscribed to each message, and sending the message to these subscribed clients.
    • The Broker also holds the session data of all clients that have persistent sessions, including subscriptions and missed messages.
    • Also Broker is responsible for the the authentication and authorization of clients.
    • So simply speaking, The Broker is the heart/core of MQTT through which every message must pass. So it arises the need for a Broker being highly scalable, integratable into backend systems, easy to monitor, and lastly failure-resistant.

    How Communication happens in MQTT -
    The MQTT connection is always between one client and the broker.
    Clients never connect to each other directly.
    To initiate a connection, the client sends a CONNECT message to the broker. The broker responds with a CONNACK (acknowledment for connection )message and a status code. Once the connection is established, the broker keeps it open until the client sends a disconnect command or the connection breaks.
    So this was the basic introduction about MQTT.

    For using MQTT in Javscript, ECLIPSE have developed an awesome library known by Eclipse Paho JavaScript Client. Check it out, if someone want to integrate MQTT client in Javascript

Comments

Popular posts from this blog

What the hack is Call, bind & apply

What is IIFE in Javascript ?