Tech Solution Stack

Tech Solution Stack – Tech Solution Stack is a blog sharing practical guide and tutorials on modern tech solutions for developers.

ads header

Thursday, November 13, 2025

Getting Started with MQTT using Mosquitto and .NET client as Publisher and Subscriber

Getting Started

In the world of IoT and real-time communication, MQTT (Message Queuing Telemetry Transport) has become one of the most popular lightweight messaging protocols. It is designed for scenarios where network bandwidth and device resources are limited, making it perfect for sensors, controllers, and connected applications. If you want to know more about MQTT vs AMQP refer to our earlier blog post MQTT vs AMQP: Key Differences, Use Cases, and Tools

In this blog, we’ll walk through a hands-on introduction to MQTT using the Mosquitto broker. We’ll learn how to:

  •  Use Mosquitto clients (mosquitto_pub and mosquitto_sub) to publish and subscribe to MQTT topics.
  • Build a Python client for subscribing and processing messages.
  • Use QoS level
  • Set up secure communication using TLS to ensure data privacy and authentication.

By the end of this tutorial, we’ll have a complete understanding of how MQTT works in practice, from publishing messages to subscribing clients, all running over a secure, lightweight messaging infrastructure.

Setting Up the Mosquitto MQTT Broker

Before we start publishing and subscribing to messages, let’s set up our MQTT broker. We’ll use Eclipse Mosquitto, one of the most popular open source MQTT brokers, known for its simplicity and reliability.

If you want to know more about software licensing type then go for our previous blog post Software Licenses: Open Source vs Proprietary

Install Mosquitto (Windows OS)

Download the Mosquitto installer from the official Mosquitto website https://mosquitto.org/download/

Run the installer and select the options to install both broker and client tools.

Once installed, verify the installation by running command  mosquitto -v
Verify the Broker is Running

Once the broker is up, test its default port (1883 for non-TLS):

netstat -an | findstr 1883
If mosquito is running following result should come in response


Test Basic Publish/Subscribe

Open two terminals, in terminal 1 subscribe to a topic and in terminal 2 publish to a topic.

Terminal 1 – Subscribe to a topic:

mosquitto_sub -h localhost -t test/topic

Terminal 2 – Publish a message:

mosquitto_pub -h localhost -t test/topic -m "Hello MQTT!"

As soon as the message will publish in Terminal 2, the same will appear in terminal 1 

Creating a .NET MQTT Client to Subscribe and Receive Messages

Once the Mosquitto broker is live, we can connect to it programmatically using an MQTT client library. In .NET, the most popular and reliable choice is MQTTnet, an open-source library that fully supports MQTT v3.1.1 and v5.

Let’s walk through the process of building a simple subscriber in C#.

1. Create a New .NET Console Application

Open visual studio and create a new .NET Console Application “MQTT.NETSubscriber”

2. Install the MQTTnet Package

Right click on solution project and click on Manage Nuget Package to open it. Browse for MQTTnet library and install the latest stable version.

Note: - In the code example I have used MQTTNet v3.1.2 for .NET framework 4.7.2
If you are using .NET Core feel free to use the higher compatible version

3. Write the MQTT Subscriber Code

I have created a separate class file having methods to create MQTT instances, connect to MQTT broker and subscribe for events from topic. In the main method I am calling for subscription.

The full project can be found in the GITHub repo. 

Program.cs code

using System.Threading.Tasks;

using System.Configuration;

namespace MQTT.NETSubscriber

{

    public class Program

    {

        static async Task Main(string[] args)

        {

            string broker = ConfigurationManager.AppSettings["Broker"];

            int port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);

            string testTopic = ConfigurationManager.AppSettings["Topic"];        

MQTTSubscriber mQTTSubscriber = new MQTTSubscriber(broker, port);

            await mQTTSubscriber.ConnectAsync();

            await mQTTSubscriber.SubscribeAsync(testTopic);         

Console.WriteLine("Waiting for messages. Press any key to exit...");          

Console.ReadKey();

            await mQTTSubscriber.DisconnectAsync();

        }

    }

}

MQTTSubscriber.cs code

public class MQTTSubscriber

{

    private MqttFactory _factory;

  private IMqttClient _client;

    private IMqttClientOptions _clientOptions;

    public MQTTSubscriber(string broker,int? port)

    {

        // Create a new MQTT client

        _factory = new MqttFactory();

        _client= _factory.CreateMqttClient();

        // Configure client options

        _clientOptions = new MqttClientOptionsBuilder()   

.WithTcpServer(broker, port)

        .WithClientId("DotNetSubscriber")

        .Build();

        // Attach message handler (old syntax for v3.x)    

_client.ApplicationMessageReceivedHandler =

            new MqttApplicationMessageReceivedHandlerDelegate(OnMessageReceived);

    }

    public async Task ConnectAsync()

    {   

Console.WriteLine("Subscriber is connecting to MQTT broker...");

        await _client.ConnectAsync(_clientOptions);   

Console.WriteLine("Subscriber connected successfully!");

    }

    public async Task SubscribeAsync(string topic)

    {

        if (!_client.IsConnected)

        {         

Console.WriteLine("Client not connected. Connecting now...");

            await ConnectAsync();

        }

        await _client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic(topic).Build());  

Console.WriteLine($"Subscriber subscribed to topic: {topic}");

    }

    public async Task DisconnectAsync()

    {

        await _client.DisconnectAsync();

Console.WriteLine("Disconnected from MQTT broker.");

    }

    #region private methods

    // Message handler (for v3.x)

    private void OnMessageReceived(MqttApplicationMessageReceivedEventArgs e)

    {

        string topic = e.ApplicationMessage.Topic;

        string message = Encoding.UTF8.GetString(e.ApplicationMessage.Payload ?? Array.Empty<byte>());

Console.WriteLine($"Message received on topic '{topic}': {message}");

    }

    #endregion

}

Check the result

Run the .NET program

Open a command prompt and use Mosquitto_pub command to publish a message to topic TestTopic1 like below :

>mosquitto_pub -h localhost -t TestTopic1 -m "Hello MQTT!!!!!!!"

You can find the message is printing in .NET program console window.

Creating a .NET MQTT Client to Publish Messages

We’ll use the same MQTTnet v3.1.2 library, but this time focus on sending messages to a topic that our subscriber can receive.

public class MQTTPublisher

{

    private readonly MqttFactory _factory;

    private readonly IMqttClient _client;

    private readonly IMqttClientOptions _clientOptions;

    public MQTTPublisher(string broker, int? port)

    {

        // Create MQTT client

        _factory = new MqttFactory();

        _client = _factory.CreateMqttClient();

        // Configure client options

        _clientOptions = new MqttClientOptionsBuilder()        

.WithTcpServer(broker, port)       

.WithClientId("DotNetPublisher")

            .Build();

    }

    // Connect to broker

    public async Task ConnectAsync()

  {      

Console.WriteLine("Publisher is connecting to MQTT broker...");

        await _client.ConnectAsync(_clientOptions);     

Console.WriteLine("Publisher connected successfully!");

    }

    // Publish message to topic

    public async Task PublishAsync(string topic, string message)

    {

        if (!_client.IsConnected)

        {       

Console.WriteLine("Client not connected. Connecting now...");

            await ConnectAsync();

        }

        var mqttMessage = new MqttApplicationMessageBuilder()          

.WithTopic(topic)         

.WithPayload(Encoding.UTF8.GetBytes(message))         

.WithQualityOfServiceLevel(MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce)       

.WithRetainFlag(false)

            .Build();

        await _client.PublishAsync(mqttMessage);     

Console.WriteLine($"Message published to '{topic}': {message}");

    }

    // Disconnect from broker

    public async Task DisconnectAsync()

    {

        await _client.DisconnectAsync();     

Console.WriteLine("Disconnected from MQTT broker.");

    }

}

Change the program.cs file to invoke publisher methods . So once the program will run both publisher and subscriber should connect to MQTT broker where publisher will be ready to publish and subscriber will be listening the topic.

static async Task Main(string[] args)

{

    string broker = ConfigurationManager.AppSettings["Broker"];

    int port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);

    string topic = ConfigurationManager.AppSettings["Topic"];

    // Create both subscriber and publisher instances

    var subscriber = new MQTTSubscriber(broker, port);

    var publisher = new MQTTPublisher(broker, port);

    // Connect both

    await subscriber.ConnectAsync();

    await subscriber.SubscribeAsync(topic);

    await publisher.ConnectAsync();

    Console.WriteLine("Publisher connected. Type messages to publish (type 'exit' to quit).");

    // Publish messages and see them received by the subscriber

    while (true)

    {

        Console.Write("Message: ");

        string message = Console.ReadLine();

        if (string.Equals(message, "exit", StringComparison.OrdinalIgnoreCase))

            break;

        await publisher.PublishAsync(topic, message);

    }

    // Disconnect both

    await publisher.DisconnectAsync();

    await subscriber.DisconnectAsync();

    Console.WriteLine("Disconnected both clients. Press any key to exit...");

    Console.ReadKey();

}

Now we can see the result that once we publish any message, the same message is available to subscriber.

Understanding and Implementing MQTT QoS Levels in .NET

let’s dive into the next topic in our list QoS (Quality of Service) Levels. This is one of the most important MQTT concepts for reliable message delivery.

MQTT defines three Quality of Service (QoS) levels that determine how reliably messages are delivered between the publisher and subscriber.

QoS

Level Name

Guarantee

Description

0

At most once

No acknowledgement

Message is delivered once, if possible, but can be lost. Fastest but least reliable.

1

At least once

Guaranteed delivery, may be duplicate

Broker stores message until it gets an acknowledgment (PUBACK). Subscriber may get duplicates.

2

Exactly once

Guaranteed delivery, exactly once

Safest but slowest — ensures message is received only once using a 4-step handshake.

1aWe can configure QoS in both publisher and subscriber.

Set QoS in Subscriber.cs

public async Task SubscribeAsync(string topic, int qosLevel = 1)

{

    if (!_client.IsConnected)

    {

        Console.WriteLine("Client not connected. Connecting now...");

        await ConnectAsync();

    }

    var qos = (MQTTnet.Protocol.MqttQualityOfServiceLevel)qosLevel;

    await _client.SubscribeAsync(new MqttTopicFilterBuilder()

        .WithTopic(topic)

        .WithQualityOfServiceLevel(qos)

        .Build()

        );

    Console.WriteLine($"Subscriber subscribed to topic: {topic} with QoS {qosLevel}");

}

In previous publisher code we are already used QoS 1

Setting Up Secure MQTT Communication Using TLS

As MQTT is often used in IoT systems and enterprise integrations, securing communication between clients and brokers is essential. Without encryption, sensitive information can be intercepted or tampered with during transmission. To protect your data, MQTT supports Transport Layer Security (TLS) ensuring that messages are securely transmitted and both client and broker can authenticate each other.

1.      Get the CA certificate

The very first step is to get the certificate from trusted certificate authority. It’s like a notary office that says: “I verify that this organization’s identity is legitimate.” It owns a private key (ca.key) and public certificate (ca.crt).

2.      Create the Broker Certificate (Server Certificate)

Our MQTT broker (Mosquitto) needs it’s own certificate like identity card. This certificate (server.cert) contains it’s public key and identity info (like CN=Localhost). But the world won’t trust this certificate unless signed by a CA.we have to sign the broker certificate using CA private key.

Step1

So, first we have to create the private key of the broker (server.key) using openssl .

Step2

Then create a certificate signing request (CSR).

CRS contains

1.public key derived from private key

2.The broker’s identity details like CN,organization, etc

Step3

Sign the broker CSR with CA certificate and key to generate server certificate

3.      How MQTT Client(publisher/subscriber) authenticate MQTT broker

When client connects to broker, the broker presents it’s certificate(server.cert). The client then check who signed it by seeing the CA info inside it.The client is already having the CA’s public certificate (CA.cert) to verify the signature.

If the verification succeeds then broker is authentic else no.

Setting Up Secure MQTT Communication Using TLS

As MQTT is often used in IoT systems and enterprise environments, securing communication between clients and brokers is essential. Without encryption, sensitive data can be intercepted or tampered with during transmission. To ensure confidentiality and authenticity, MQTT supports Transport Layer Security (TLS)  which encrypts messages and allows both client and broker to verify each other’s identity.

1.Get the CA Certificate

The first step is to get a certificate from a trusted Certificate Authority (CA).
Think of the CA like a digital notary office that says: “I verify that this organization’s identity is legitimate.”

The CA owns:

  • a private key (ca.key) – used to sign other certificates
  • a public certificate (ca.crt) – used by clients to verify signatures

If you’re testing locally, you can create your own self-signed CA using OpenSSL.

2.Create the Broker Certificate (Server Certificate)

Your MQTT broker (Mosquitto) needs its own digital identity card — the server certificate (server.crt).
This file contains the broker’s public key and identity details (like CN=localhost).

However, the world (clients) won’t trust this certificate unless it’s signed by the CA.
That’s why we must use the CA’s private key to sign the broker’s certificate.

Step 1: Create the broker’s private key

openssl genrsa -out server.key 2048

Step 2: Create a Certificate Signing Request (CSR)

openssl req -new -key server.key -out server.csr

The CSR includes:

  • The broker’s public key
  • Identity details such as CN (Common Name), Organization, etc.

Step 3: Sign the CSR using the CA’s certificate and key

openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \

-out server.crt -days 365 -sha256

This produces the server certificate (server.crt) signed by the CA.

3.How MQTT Clients Authenticate the Broker

When a client (publisher/subscriber) connects to the broker:

  1. The broker presents its certificate (server.crt).
  2. The client checks who signed it by reading the CA information inside the certificate.
  3. The client uses its trusted CA certificate (ca.crt) to verify the broker’s certificate signature.

If the verification succeeds, the client trusts the broker and establishes a secure TLS connection.
If not, the connection is rejected ensuring that the client never talks to an untrusted server.

Generated documents summary Table

File Name

Description

Purpose

Used By

CA.key

Private key of the CA

Used to sign and issue other certificate

CA

CA.cert

Public certificate of the CA

Shared with clients so they can verify certificates signed by CA

Client

Server.key

Private key of the MQTT Broker

Used to encrypt and authenticate messages from the broker

Broker

Server.csr

Certificate signing request

Contains broker’s public key and identity details sent to CA for signing

Temporary during creation

Server.cert

Signed certificate from MQTT Broker

Proves the broker’s identity to client. Used in TLS handshake

Broker

To be continued for..

4.Configuring Mosquitto for TLS Communication

5. Configuring .NET MQTT Client for Secure TLS Connection


Wednesday, October 29, 2025

The Math Behind AI

 

Introduction

Artificial Intelligence and Machine Learning may sound like complicated topics filled with difficult math and smart computers, but at the core, they are all about mathematics.

Whenever we train an AI model, try to improve its performance, or use methods like gradient descent, we are actually using math. It is the language that helps machines learn and make decisions.

Before moving to advanced AI topics, it is important to start with the basics, and one of the most important foundations is Algebra.

Algebra helps us find unknown values, understand relationships, and discover patterns, just like how AI learns patterns from data.

In this post, we will see how simple algebra equations can help solve real life problems and how we can use Python to visualize them.

What is Algebra

Solving for unknows within system of linear equations is Algebra

Problem Statement

The Cop has started to catch bank robber in a van of speed 180km/h. Bank robber has started for rubbery 5 minutes ahead of police van in a car of speed 150 km/h. How long the cop takes to catch the rubber and what distance they have travelled? Ignore the traffic and acceleration etc.

Solution

There are unknows in this problem statement which can be solved by algebra.
Consider d for distance and t for time.
Police van has a speed of 150 km/h
=>d/t = 150 mk/h
=>d/t = 2.5 km/minute ---------------------------- Equation1

Bank robber van has a speed 180km/h and started 5 minutes later than police van.
=>d/(t-5) = 180 km/h
=>d/(t-5) = 3 km/h
=>d = 3t – 15 -----------------------------------------Equation2

From the above 2 equations
=>3t-15 = 2.5t
=>0.5t = 15
=>t = 30 minutes

Using the value of t in equation 2
d = 3x30 – 15
=>d = 75 kilometers

From the above result we are clear that after a distance of 75 kilometers police can catch the rubber in 30 minutes of drive.

Using pen and paper we can plot the graph for the above to equations to get the unknowns. Same can be done using python code as well.
Let’s try using python programming.

Find the unknowns in Python program using NumPy and matplotlib

Download the following packages if not downloaded already.
pip install NumPy
pip install matplotlib

import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, 40, 1000) # start, finish, n points
dr = 2.5 * t
dc = 3*t - 15
#Matplotlib command that creates a Figure and Axes — the two main objects used for plotting.
fig, ax = plt.subplots()
plt.title('Bank Robber Caught Sample Plot')
plt.xlabel('time in minutes')
plt.ylabel('distance in km')
ax.set_xlim([0, 40])
ax.set_ylim([0, 100])
ax.plot(t, dr, c='green')
ax.plot(t, dc, c='blue')
plt.axvline(x=30, color='yellow', linestyle='--')
plt.axhline(y=75, color='yellow', linestyle='--')
# To show the graph 
plt.show()


What is Tensor?

A tensor is a mathematical object that generalizes scalars, vectors and matrices to higher dimensions. Tensors are widely used in fields like physics, engineering and machine learning to represent and manipulate data.

Dimension

Mathematical Name

Description

0

Scalar

Only magnitude of x

1

Vector

An array. [x, y]

2

Matrix

Square or a table

3

3-Tensor

Cube or 3D table

n

n-Tensor

Nth dimension

 

Scalars in Python

Scalar is just a value like integer 25
In python declare a variable and assign 25 which is a scalar value.

Widely used two automatic differentiation libraries in Python are Pytorch and TensorFlow.Let’s see the scalar value in these libraries

Scalar in Pytorch

Install libraries if not install already.
pip install TensorFlow
pip install torch torchaudio

Scalar in TensorFlow

>>> import tensorflow as tf
>>> x = tf.Variable(25, dtype=tf.int32)
>>> print(x) #returns <tf.Variable 'Variable:0' shape=() dtype=int32, numpy=25>
>>> print(x.shape) #returns ()

Vectors

The vector is 1-dimensional array of numbers. Example [x1, x2] = [10,20]
The vector of length 2 represents a location in 2-dimensional matrix
The vector of length 3 represents a location in 3-dimensional matrix
The vector of length n represents a location in n-dimensional tensor

Vector Transposition  

The concept of converting row vector to column vector and vice versa is called vector transposition.
Example: [x1, x2, x3] T = [x1
                                              x2
                                              x3]

Let’s see the example in Python code


Revisit again to get more content here ...

Thursday, September 18, 2025

How to Use Node-RED to Store API Data into SQL Server

Introduction

Node-RED is an open-source, low-code programming tool developed by IBM. This is licensed under the Apache License 2.0, a permissive open-source license. If you want to know more about software licenses then visit our earlier post Software Licenses: Open Source Vs Proprietary.
In this tutorial we will use Node-RED for API integration with SQL Server database.



Use cases of Node-Red
·        IoT dashboards (collecting sensor data into a database).
·        API integration (connecting REST APIs to SQL Server/NoSQL).
·        Automation workflows (like ETL pipelines, smart home automation).
·       
Data processing pipelines (cleaning & transforming data before storage).

Let's begin

First, we will do the prerequisite setup by installing only required softwires before entering into the problem statement example.
In this example we will use any readily available API endpoint which should return sample sensor data in JSON format. We will create Node-Red flow to read the API response, process the data and save into SQL Server database table. Finally, I will attach the flow JSON file for your reference.
Let’s make a start

Prerequisites

·        Install Node.js if not installed already
·        Install Node-RED
·        Run SQL Server
·        Install node MSSQL

Install 
Node.js
Go to Node.js official site https://nodejs.org/ and download long term support version of Node.js. We will download and install v22.19.0(TLS) for windows

On successful installation use the following command to check the installed 
version of Node.js and npm -v

Install Node-RED
Run the following command to install node-red. The -g flag means installation is global, Node-RED will be installed in your system-wide npm global folder, not in the current directory. Avoid permission issues with --unsafe-perm 


Now install Node-Red node MSSQL by the command npm install node-red-node-mssql
Start the Node-Red
In command prompt type node-red and hit enter to start the Node-Red server. Once the server is running browse the url to lunch the canvas as shown below

I hope we are all set with prerequisites, let’s move for creating the Node-red flow step by step.
STEP:1 Create Inject Node
Inject node the first node in canvas. The Inject node lets you manually or automatically send a message into a flow. Think of it as a trigger. It’s often used to start a flow for testing or to send periodic data. Drag the inject node and keep in canvas as shown in diagram and double click to edit. Keep a name as per your choice. The name I have given is Start.

STEP:2 Create HTTP Request Node
The HTTP request node is used to make HTTP(S) calls (GET, POST, PUT, DELETE, etc.) from your Node-RED flow.It acts like a built-in API client (similar to Postman or curl).
You can use it to consume REST APIs or send data to web services.Drag an HTTP Request node, connect it with inject node. Double click to configure.
Method: Get
Url: https://api.thingspeak.com/channels/9/feeds.json?results=5
Returns: a parsed JSON object


Drag a Debug node and connect with HTTP Request node to text the flow so far that we are receiving the API response. Deploy the code and debug to see the data as shown below. If you see data then so far the configuration is correct.

STEP:2 Create Table and Procedure in Database
Create a database or use if any existing database for this example.
Create the following table to store the sensor data received from API endpoint
  Create table SensorData(
  entityId INT,
  light float,
  outsideTemp float,
  timestamp datetime
  ); 
  --Create a procedure to insert data into this table Sensordata as following
  CREATE PROCEDURE sp_InsertSensorData
  @entityId INT,
  @light float,
  @outsideTemp float,
  @timestamp datetime
  AS
  BEGIN
      INSERT INTO SensorData(entityId,light,outsideTemp,timestamp)
      VALUES(@entityId,@light,@outsideTemp,@timestamp);
  END;
  
STEP:3 Function Node to prepare SQL query

The Function node allow us write custom JavaScript code to process, transform, or generate messages in a Node-RED flow.

It is the logic/brain of our workflow. We will create this node to form the SQL query out of API response data to insert into SQL Server database table.
Delete the debug node and drag the function node to the canvas, connect it to the HTTP Request node. Double click to configure.
Name: Prepare SQL Script
Function Code:
  let feeds = msg.payload.feeds || [];
if (feeds.length === 0) {
    node.error("No feeds found in API response", msg);
    return null;
}
//Extract the first feed from the API response
let feed = msg.payload.feeds[0];

//Construct the SQL query for the store procedure
msg.topic =`
    EXEC dbo.sp_InsertSensorData
        @entryId=${feed.entry_id},
        @light=${parseInt(feed.field1)},
        @outsideTemp=${parseInt(feed.field2)},
        @timestamp='${feed.created_at}'
        `;
        return msg;

  
Attach a debug node to test the flow, if all are working fine then result should appear like this
STEP:4 MSSQL Node to execute the procedure & save data into database table
The MSSQL node in Node-RED lets you connect to a Microsoft SQL Server database and run SQL queries or stored procedures.
Drag an MSSQL node, connect it with function node. Double click to configure.
Enter your SQL Server credentials.
Deploy the flow and click on Start button. If your SQL Server connection is active then new record will be successfully inserted into the table.
You can download and import my ready-made Node-RED flow from the attached
flow.json

Conclusion:

In this post, we explored how to build an end-to-end data pipeline in Node-RED to consume sensor data from an external API and store it into a SQL Server database. Along the way, we learned about:
Installing and configuring Node-RED.
Using the Inject, HTTP Request, Function, and MSSQL nodes.
Executing stored procedures from Node-RED and verifying data insertion in SQL Server.
 
With this flow, you now have a low-code integration between IoT-style APIs and enterprise-grade databases. Node-RED’s flexibility means you can extend this further — add dashboards, trigger alerts, or connect additional APIs with minimal effort. 
Whether you are working on IoT projects, automation workflows, or enterprise integrations, Node-RED provides a powerful and user-friendly way to connect data from anywhere to anywhere.






Sunday, August 31, 2025

MQTT vs AMQP: Key Differences, Use Cases, and Tools

 

Introduction

We need to transfer data from one system to other in the form of events, messages for various reasons. The data can be the real time data, time series data, configuration information etc. Looking into the system requirement we often choose many different ways to deal with this data transformation i.e. REST API based approach, Web socket, MQTT, AMQP etc. In this article we will focus on MQTT vs AMQP. How these two approaches are widely used serving different purposes. What is the basic differences, when to choose which one, and tools available from each type. Let’s get started …

What Is MQTT

MQTT stands for Message Queuing Telemetry Transport is a lightweight, publisher subscriber messaging protocol designed for efficient communication between devices, especially in scenarios where network bandwidth is limited or devices are resource constrained.

We talked about network bandwidth is limited and resource constrained device. It means situations where data speed, reliability, or cost is a problem.

Examples:

A remote weather station sensor in a village uploads temperature data over a weak mobile signal.

Networks that have frequent drops or delays (satellite, ship-to-shore communications, mining sites).

What is AMQP

AMQP stands for Advanced Message Queuing Protocol. It is a powerful messaging protocol used for reliable and secure communication between applications. Unlike MQTT, which is mainly used in lightweight IoT systems, AMQP offers advanced features like message queuing, routing, guaranteed delivery, and transaction support. This makes it a good choice for complex systems such as banking, financial services, and enterprise applications where every message must be delivered safely and in order.

Difference between MQTT & AMQP

Features

MQTT

AMQP

Primary use cases

IoT, sensors, mobile apps

Enterprise systems, financial services, business applications

Architecture

Publisher - Subscriber

Message queuing

Message Size

Light weight message

Large complex message

Reliability

Basic reliability (QoS 0, 1, 2)

Strong reliability (transactions, acknowledgments, guaranteed delivery)

Overhead

Low overhead due to minimal packet size

Higher overhead due to advanced features

Security

TLS/SSL

Strong built-in security with authentication, encryption, and authorization

MQTT Use cases

1.   Use MQTT when devices are resource oriented (Low CPU, memory, battery)

2.   While dealing with low bandwidth or unstable network (Mobile, satellite or remote IoT)

3.   While the requirement is real-time telemetry data (sensor reading, GPS update)

4.   When the system requirement is simple publisher / subscriber pattern

In sort use MQTT when we need fast and lightweight communication with minimal overhead.

AMQP Use cases

1.   When we need guaranteed message delivery, no data loss allowed.

2.   When the system required complex routing (one message can be routed into multiple queues)

3.   While building enterprise grade system with multiple integrations

4.   Transactions and reliable acknowledgement (Banking & Financial transaction)  

   In sort use AMQP while security, interoperability and enterprise compliance are    priorities.

MQTT tools

Tool / Library

Type

License

Notes

Eclipse Mosquitto

Broker

Eclipse Public License 2.0

Lightweight, widely used in IoT.

HiveMQ (Community Edition)

Broker

Apache License 2.0 (Community)

Free for small-scale; Enterprise version is commercial.

EMQX

Broker

Apache License 2.0 (Open-Source Core)

Enterprise version available (commercial).

VerneMQ

Broker

Apache License 2.0

Focus on scalability & clustering.

Eclipse Paho

Client Library

Eclipse Public License 2.0

Official client libraries for multiple languages.

MQTT.js

Client Library

MIT License

Popular Node.js MQTT client.

paho-mqtt (Python)

Client Library

Eclipse Public License 2.0

Python client for MQTT.

M2Mqtt (.NET)

Client Library

Apache License 2.0

Widely used in .NET IoT projects.

AMQP Tools

Tool / Library

Type

License

Notes

RabbitMQ

Broker

Mozilla Public License 2.0

Most popular AMQP broker.

Apache Qpid

Broker

Apache License 2.0

Apache’s AMQP implementation.

ActiveMQ Artemis

Broker

Apache License 2.0

Enterprise messaging, supports AMQP + other protocols.

Azure Service Bus

Cloud Service

Commercial (Microsoft)

Fully managed cloud service.

AMQP.Net Lite

Client Library

Apache License 2.0

Lightweight AMQP client for .NET.

Qpid Proton

Client Library

Apache License 2.0

Multi-language AMQP client.

rhea (Node.js)

Client Library

Apache License 2.0

Node.js client for AMQP.

Apache NMS (for .NET)

Client API

Apache License 2.0

Messaging client for AMQP & JMS-like APIs.

If you want to know more about different types of software licenses (like Apache 2.0, MIT, or MPL), check out my Software Licenses: Open Source vs Proprietary where I explained them in detail.

Conclusion

Both MQTT and AMQP are powerful messaging protocols, but they serve different purposes.

  • MQTT is lightweight, simple, and highly efficient, making it the go-to choice for IoT devices, sensors, and real-time telemetry where bandwidth and resources are limited.
  • AMQP is heavier but far more feature-rich, making it suitable for enterprise systems, financial services, and applications where reliability, guaranteed delivery, and complex routing are critical.

When choosing between the two, always look at your system requirements, if your focus is on speed and efficiency for small devices, go with MQTT. If your priority is robustness, reliability, and enterprise-grade workflows, then AMQP is the better fit.

In short:
 Use MQTT when you need lightweight IoT communication.
 Use AMQP when you need enterprise-level reliability and advanced messaging patterns.




Powered by Blogger.

Subscribe by Email

Search This Blog

Post Top Ad

ad728