Boost IoT Performance with mica-mqtt: A High‑Performance Java AIO MQTT Solution
The article introduces mica-mqtt, a Java AIO‑based open‑source MQTT component offering simple, low‑latency, high‑performance IoT messaging, outlines its extensive features, typical use cases, recent updates, migration steps, and provides code examples and documentation links for developers.
1. Introduction
mica-mqtt is an open‑source MQTT component built on Java AIO , designed to be simple, low‑latency, and high‑performance for IoT applications. It integrates easily into existing services and reduces development costs for custom IoT platforms.
2. Features
Supports MQTT v3.1, v3.1.1, and v5.0 protocols.
Supports WebSocket sub‑protocol (compatible with mqtt.js).
Provides HTTP REST API (documentation referenced).
Includes MQTT client and server implementations.
Supports MQTT will messages and retained messages.
Enables custom message processing and cluster forwarding.
Offers an Alibaba Cloud MQTT connection demo.
Can be compiled to a native executable with GraalVM.
Provides a Spring Boot starter (
mica-mqtt-spring-boot-starter) for quick integration.
Integrates with Prometheus and Grafana for monitoring.
Implements clustering via Redis pub/sub (see
mica-mqtt-brokermodule).
3. Use Cases
IoT cloud MQTT broker.
Edge‑side message communication for IoT.
Group chat (IM) applications.
Message push services.
Simple, easy‑to‑use MQTT client implementations.
4. Update Log (v2.1.0 – 2023‑03‑05)
Incompatible interface parameter adjustments for easier use.
Core refactoring and compatibility with newer Spring Boot versions (2.1.0.RELEASE+).
SSL support for mutual authentication.
Bug fixes for will‑message handling and typo corrections.
Dependency upgrades.
5. Migration Guide
Split
mica-mqtt-coreinto
mica-mqtt-clientand
mica-mqtt-serverto avoid dependency conflicts.
Moved
HexUtilfrom
net.dreamlu.iot.mqtt.core.util.HexUtilto
org.tio.utils.mica.HexUtils.
5.1 Client
5.1.1 Subscription Callback Interface Changes
When using
mica-mqtt-client-spring-boot-starter, annotation‑based subscriptions are supported.
The
IMqttClientMessageListener#onMessage(ChannelContext context, String topic, MqttPublishMessage message, ByteBuffer payload)method now includes
contextand
messageparameters.
<code>// Message subscription example (subQos0)
client.subQos0("/test/#", (context, topic, message, payload) -> {
logger.info(topic + '\t' + ByteBufferUtil.toString(payload));
});</code>5.1.2 SSL Mutual Authentication Support
<code>mica:
ssl:
enabled: false # Set true to enable SSL; from 2.1.0 supports mutual auth
keystore-path: # Path to keystore for mutual auth (classpath:/ supported)
keystore-pass: # Keystore password (required for mutual auth)
truststore-path: # Path to truststore for mutual auth (optional)
truststore-pass: # Truststore password (optional)
client-auth: none # Options: none, optional, require</code>SSL modes:
ClientAuth NONE – server only requires SSL, no client certificate.
ClientAuth OPTIONAL – server negotiates client authentication; client must provide truststore.
ClientAuth REQUIRE – client must provide both truststore and keystore certificates.
5.1.2.1 IMqttMessageListener Adjustments
The
IMqttMessageListeneronMessage signature now includes
topicand
qoS, and the
messageparameter is the raw
MqttPublishMessageto access MQTT 5.x properties.
<code>/**
* Listener for received messages
* @param context ChannelContext
* @param clientId client identifier
* @param topic topic name
* @param qoS MQTT QoS level
* @param message MqttPublishMessage instance
*/
void onMessage(ChannelContext context, String clientId, String topic, MqttQoS qoS, MqttPublishMessage message);
</code>6. Documentation and Examples
mica-mqtt-client documentation.
mica-mqtt-server documentation.
mica-mqtt-client-spring-boot-starter documentation.
mica-mqtt-server-spring-boot-starter documentation.
mica-mqtt HTTP API documentation.
mica-mqtt release notes.
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.