Unlock Low-Latency IoT Messaging with mica-mqtt: Features, Use Cases, and Updates
The article introduces mica-mqtt, a Java AIO‑based low‑latency MQTT component, outlines its extensive features and typical IoT scenarios, and details the latest v2.3.0 release notes, code examples, and its role in the BladeX Links platform.
1. Introduction
mica-mqtt is a simple, low‑latency, high‑performance MQTT IoT open‑source component built on java aio . It is easy to integrate into existing services and to extend, reducing the cost of building a custom IoT platform.
2. Features
Supports MQTT v3.1, v3.1.1 and v5.0 protocols.
Supports WebSocket MQTT sub‑protocol (compatible with mqtt.js).
Provides HTTP REST API (documentation referenced).
Offers MQTT client library.
Offers MQTT server implementation.
Supports MQTT Last Will messages.
Supports retained MQTT messages.
Custom message (mq) processing and forwarding for clustering.
Demo for connecting to Alibaba Cloud MQTT.
Supports GraalVM compilation to native executable.
Spring Boot starter for quick integration (mica-mqtt-spring-boot-starter).
Prometheus + Grafana integration via the starter.
Cluster support based on Redis pub/sub (see mica-mqtt-broker module).
3. Use Cases
IoT cloud‑side MQTT broker.
Edge‑side IoT message communication.
Group‑based instant messaging.
Message push services.
Simple, easy‑to‑use MQTT client.
4. Release Notes
v2.3.0 – 2024‑05‑26
Optimized MqttQoS enum to MqttQoS.QOS0 (breaking change).
Added stop method to fully halt mica-mqtt-client.
Added schedule and scheduleOnce methods to MqttClient (requires custom thread pool for long‑running tasks).
Optimized device offline handling in mica-mqtt-server.
Added user binding via
Tio.bindUser(context, username)in server.
Fixed @MqttClientSubscribe type error in spring‑boot starter.
Fixed reconnection failure issue reported by @YYGuo.
5. Update Details
5.1 mqtt‑client stop
The client now supports a stop operation using a time‑wheel based heartbeat thread, making it usable in more scenarios.
5.2 mqtt‑client schedule
<code>MqttClient client = MqttClient.create()
.ip("127.0.0.1")
.port(1883)
.username("mica")
.password("mica")
.connectSync();
// Use schedule to publish periodically
client.schedule(() -> {
client.publish("/test/client", "mica最牛皮".getBytes(StandardCharsets.UTF_8));
}, 2000);
</code>5.3 mqtt‑server username binding
Version 2.3.0 uses
Tio.bindUser(context, username)to bind the connection username. Retrieve it with
context.getUserId(). Get the set of connections for a username via:
<code>Set<ChannelContext> usernameSet = Tio.getByUserid(context.tioConfig, "username");
</code>6. BladeX Links Preview
Thanks to WingShen for adopting mica-mqtt as the foundation of the BladeX‑Links IoT platform. BladeX‑Links is now feature‑complete and in the polishing stage; interested parties can follow its progress.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
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.