Getting Started with NanoMQ: Fast Edge MQTT Broker Deployment and Usage
This guide introduces NanoMQ, a lightweight high‑performance MQTT broker for edge and IoT scenarios, outlines its key features, core advantages, and provides step‑by‑step Docker deployment, client connection, and publishing examples with PHP code.
Overview
NanoMQ is an edge‑focused messaging platform that provides a high‑performance MQTT broker and a lightweight message bus for software‑defined vehicles. It is built on the NNG asynchronous I/O and multithreaded model, with deep MQTT protocol optimizations.
Key Features
Full MQTT 5.0 support : Compatible with MQTT 5.0 and 3.1.1 and works with standard MQTT SDKs.
MQTT Bridge : Built‑in multi‑cloud bridging for synchronizing data across cloud endpoints.
Rule Engine : Simple on‑device rule engine; can be integrated with eKuiper for stream analytics.
Message Persistence : Local caching and durable storage for bridge messages, supporting offline‑store‑and‑forward.
Rich Integration APIs : Event‑driven WebHook and HTTP APIs for easy integration.
Multi‑Protocol Gateway : Supports nanomsg, ZeroMQ, WebSocket and other protocols with optional encryption.
MQTT STREAM : Treats all messages of a topic as a persistent data stream that can be queried, improving reliability in poor network conditions.
Core Advantages
Ultra‑lightweight : The broker can start with as little as 200 KB of memory.
Fully Asynchronous I/O : Actor‑model parallelism for MQTT workloads.
Multithreaded Parallelism : Strong SMP support and scalable performance on multi‑core CPUs.
High Throughput : Capable of handling millions of messages per second at the edge.
Cross‑Platform : Runs on any POSIX‑compatible system.
Interoperability : Transparent data model and extensible interfaces for integration with edge frameworks.
Quick Start with Docker
docker run -d --name nanomq \
-p 1883:1883 # MQTT
-p 8083:8083 # WebSocket
-p 8883:8883 # SSL/TLS
emqx/nanomq:latestPHP Client Example (Workerman)
Install the client library:
composer require workerman/mqttSubscriber (subscribe.php)
<?php
declare(strict_types=1);
use Workerman\Worker;
require __DIR__ . '/../../vendor/autoload.php';
$worker = new Worker();
$worker->onWorkerStart = function() {
$mqtt = new Workerman\Mqtt\Client('mqtt://127.0.0.1:1883');
$mqtt->onConnect = function($mqtt) {
$mqtt->subscribe('tinywan');
};
$mqtt->onMessage = function($topic, $content) {
echo "Subscribed topic: {$topic}
";
echo "Message content: {$content}
";
};
$mqtt->connect();
};
Worker::runAll();Run:
php subscribe.php startPublisher (publish.php)
<?php
declare(strict_types=1);
use Workerman\Worker;
require __DIR__ . '/../../vendor/autoload.php';
$worker = new Worker();
$worker->onWorkerStart = function() {
$mqtt = new Workerman\Mqtt\Client('mqtt://127.0.0.1:1883');
$mqtt->onConnect = function($mqtt) {
$mqtt->publish('tinywan', 'Hi! NanoMQ');
};
$mqtt->connect();
};
Worker::runAll();Run:
php publish.php startMotivation
Edge environments generate massive data under constrained compute, power, and network conditions. A lightweight, high‑throughput, and resilient messaging bus is required to aggregate and distribute this data. NanoMQ addresses protocol fragmentation, limited resources, and the need for reliable offline handling by providing a unified, extensible solution suitable for embedded and MEC platforms.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
