Summit
EMQ Sponsors Open Source Summit Europe 2024 | Register Now →

MQTT Broker: How It Works, Popular Options, and Quickstart

EMQX Team
Feb 1, 2024
MQTT Broker: How It Works, Popular Options, and Quickstart

What Is an MQTT Broker?

MQTT is a lightweight protocol that supports the Internet of Things (IoT).

An MQTT broker is an intermediary entity that enables MQTT clients to communicate. Functioning as a central hub, an MQTT broker efficiently handles the flow of messages between devices and applications. Specifically, an MQTT broker receives messages published by clients, filters the messages by topic, and distributes them to subscribers.

Using MQTT brokers to enable the publish/subscribe (pub/sub) communication model helps make MQTT a highly efficient and scalable protocol.

This broker-mediated communication enables a lightweight, scalable, and reliable mechanism for devices to share information in a networked environment, playing a crucial role in the establishment of efficient and responsive IoT ecosystems and other distributed applications.

Why Are MQTT Brokers Important?

The MQTT broker plays a crucial role in the MQTT architecture, as it is responsible for facilitating communication between MQTT clients (publishers and subscribers).

Here are some of the main reasons MQTT brokers are important:

  • Message routing: The MQTT broker receives messages from publishers and routes them to the appropriate subscribers based on their topic subscriptions. This ensures that messages are delivered efficiently and accurately, without the need for clients to establish direct connections with each other.

  • Scalability: MQTT brokers can handle a large number of simultaneous connections, which is essential for IoT and M2M communication scenarios, where there may be thousands or even millions of connected devices. The broker's ability to manage these connections and messages enables the MQTT protocol to scale effectively.

  • Security: MQTT brokers can provide security measures like authentication and encryption to ensure that the data transmitted between IoT devices and applications is secure. Learn more: 7 Essential Things to Know about MQTT Security 2024.

  • Integration: MQTT brokers can integrate with other communication protocols and cloud platforms to provide a complete IoT solution. For example, MQTT brokers can integrate with AWS IoT, Google Cloud IoT, or Microsoft Azure IoT Hub to provide a seamless IoT ecosystem.

  • Session management: The MQTT broker is responsible for managing client sessions, including maintaining information about the client's subscriptions and handling messages that are retained for delivery to clients when they come online. This session management feature ensures that messages are not lost when clients disconnect and later reconnect to the broker. Learn more: MQTT Persistent Session and Clean Session Explained.

MQTT Broker Architecture

The MQTT broker architecture is based on the publish-subscribe messaging pattern, which decouples message producers (publishers) from message consumers (subscribers). This architecture includes three primary components: clients, topics, and the broker.

MQTT Broker Architecture

  • MQTT Broker Server

    The MQTT broker is a server that receives messages from publishers and delivers them to subscribers based on their topic subscriptions. It manages client connections, handles subscriptions and unsubscriptions, and ensures message delivery according to the specified Quality of Service (QoS) levels.

  • MQTT Clients

    MQTT clients can be publishers, subscribers, or both. Publishers send messages to the MQTT broker, while subscribers receive messages from the broker. Clients can be any device or application that can establish a connection to the MQTT broker using the MQTT protocol, such as IoT devices, mobile applications, or other servers.

  • Topics

    Topics are hierarchical strings that define the subject or category of a message. When publishers send messages to the broker, they associate them with a specific topic. Subscribers express their interest in receiving messages by subscribing to one or more MQTT topics. The broker then routes messages to the appropriate subscribers based on their topic subscriptions.

The MQTT broker architecture can be either centralized or distributed. In a centralized architecture, a single broker handles all communication between clients. In a distributed architecture, multiple brokers work together to provide a scalable and fault-tolerant messaging infrastructure. Each broker in a distributed architecture can coordinate with other brokers to manage message routing, ensuring messages are delivered to the intended recipients.

Overall, the MQTT broker architecture provides a flexible and efficient messaging infrastructure that enables devices and applications to communicate securely, efficiently, and at scale.

EMQX

EMQX is currently the most scalable MQTT broker for IoT applications. It processes millions of MQTT messages in a second with sub-millisecond latency and allows messaging among more than 100 million clients within a single cluster. EMQX is compliant with MQTT 5.0 and 3.x. It’s ideal for distributed IoT networks and can run on the cloud, Microsoft Azure, Amazon Web Services, and Google Cloud. The broker can implement MQTT over TLS/SSL and supports several authentication mechanisms like PSK, JWT, and X.509. Unlike Mosquitto, EMQX supports clustering via CLI, HTTP API, and a Dashboard.

Try EMQX Enterprise for Free
Connect any device, at any scale, anywhere.
Get Started →

Mosquitto

Eclipse Mosquitto is an open-source MQTT broker for MQTT protocol versions 5.0, 3.1.1, and 3.1. Mosquitto is lightweight and can be installed on low-power, single-board computers or enterprise servers. The broker is written in C programming language and can be implemented on MQTT clients with a C library. It can be downloaded for Windows, Mac, Linux, and Raspberry Pi. Ready-to-install binary files are available for all operating systems. The latest version includes an authentication and authorization plugin “mosquitto-go-auth,” a web user interface for managing Mosquitto instances. It also offers a PHP wrapper “Mosquitto-PHP” for creating MQTT clients in PHP.

Learn more: Mosquitto MQTT Broker: Pros/Cons, Tutorial, and a Modern Alternative.

NanoMQ

NanoMQ is a lightweight and fast MQTT broker designed for the IoT edge. NanoMQ is implemented in purely C, based on NNG's asynchronous I/O with a multi-threading Actor Model, and fully supports MQTT 3.1.1 and MQTT 5.0 protocol versions. NanoMQ is high-performance in the context of a stand-alone broker. The fascinating advantage is its portability. It can be deployed on any POSIX-compatible platform and runs on different CPU architectures such as x86_64, ARM, MIPS, and RISC-V.

Try NanoMQ for Free
Get Started →

VerneMQ

The VerneMQ project was launched in 2014 and initially developed by Erlio GmbH. As the second broker wrote in Erlang/OTP, the project is licensed under Apache Version 2.0 and borrowed some code from the EMQX project. Regarding architectural design, VerneMQ supports MQTT message persistence in LevelDB and uses a clustering architecture based on the Plumtree library, which implements the Epidemic Broadcast Trees algorithm.

How to Choose an MQTT Broker? Resources to Help Your Evaluation Process

The following articles will help you evaluate and select the best MQTT broker for your organization’s needs.

Evaluation Criteria

MQTT Broker Comparison

MQTT Broker Benchmark Testing

Get Started with MQTT Brokers

Getting Started

You can easily get started with a free public MQTT broker or a fully managed MQTT service.

EMQ provides a free public MQTT broker built with a global multi-region EMQX Cluster. It is exclusively available for those who wish to learn and test the MQTT protocol. Please note that it’s not recommended to use it in production environments as it may pose security risks and downtime concerns.

The fully managed cloud service is the easiest way to start an MQTT service. With EMQX Cloud, you can get started in just a few minutes and run your MQTT service in 20+ regions across AWS, Google Cloud, and Microsoft Azure, ensuring global availability and fast connectivity. The latest edition, EMQX Cloud Serverless, provides a forever free 1M session minutes/month complimentary offering for developers to easily start their MQTT deployment within seconds.

Try EMQX Cloud Serverless for Free
No credit card required
Get Started →

MQTT Broker Integration

Uses of MQTT Brokers Across Various Industries

  • Real-time Monitoring and Control: MQTT brokers are central to IoT architectures, allowing devices to publish and subscribe to topics. This enables real-time monitoring and control of devices in industries such as manufacturing, smart homes, and healthcare.
  • Industrial Sensor Networks: MQTT brokers play a crucial role in collecting and disseminating data from sensors in industrial environments, supporting applications like predictive maintenance and process optimization.
  • Telemetry in Transportation: MQTT brokers enable communication between connected vehicles, supporting telemetry data exchange for applications such as vehicle tracking, performance monitoring, and traffic management.
  • Energy Management: MQTT brokers help coordinate communication between smart meters, grid equipment, and energy management systems, enhancing the efficiency, reliability, and responsiveness of energy systems.
  • Logistics and Warehousing: MQTT brokers support real-time tracking and visibility in supply chains by allowing devices to publish and subscribe to location and status updates, enhancing overall supply chain efficiency.

EMQX: World’s Most Scalable MQTT Broker

EMQX is one of the most popular MQTT brokers and has 12.9k stars on GitHub. The EMQX project was launched in 2012 and is licensed under Apache version 2.0. EMQX is written in Erlang/OTP, a programming language for building massively scalable soft real-time systems.

EMQX is the world's most scalable MQTT broker that supports advanced features such as MQTT 5.0, MQTT-SN, and MQTT over QUIC. It supports masterless clustering for high availability and horizontal scalability. EMQX 5.0, the latest version, scales to establish 100 million concurrent MQTT connections with a single cluster of 23 nodes.

EMQX offers rich enterprise features, data integration, cloud hosting services, and commercial support from EMQ Technologies Inc. Over the years, EMQX has gained popularity among enterprises, startups, and individuals due to its performance, reliability, and scalability. EMQX is widely used for business-critical applications in various industries, such as IoT, industrial IoT, connected cars, manufacturing, and telecommunications.

Product page: https://www.emqx.com/en/products/emqx

Related Resources

Talk to an Expert
Contact Us →

Related Posts

May 24, 2024Fan Wang
Comparison of Open Source MQTT Brokers 2024

Based on the criteria, we choose to focus on four popular open-source MQTT brokers EMQX, Mosquitto, NanoMQ and VerneMQ. Here is a summary of versions...