Backend Development 6 min read

Boost Your IoT Apps with mica-mqtt: A Low‑Latency Java AIO MQTT Engine

The article introduces mica-mqtt, a Java AIO‑based open‑source MQTT component offering simple, low‑latency, high‑performance IoT messaging, outlines its extensive feature set, typical use cases, recent updates, and provides detailed configuration examples for custom business thread pools and Spring Boot integration.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Boost Your IoT Apps with mica-mqtt: A Low‑Latency Java AIO MQTT Engine

Introduction

mica-mqtt is an open‑source MQTT component built on Java AIO that delivers a simple, low‑latency, high‑performance solution for IoT messaging. It is easy to integrate into existing services and reduces the cost of developing custom IoT platforms.

Features

Supports MQTT v3.1, v3.1.1, and v5.0 protocols.

Supports the WebSocket MQTT sub‑protocol (compatible with mqtt.js).

Provides an HTTP REST API (documentation referenced separately).

Includes MQTT client libraries.

Includes MQTT server implementation.

Supports MQTT will messages.

Supports retained MQTT messages.

Enables custom message (mq) processing and forwarding for clustering.

Provides an Alibaba Cloud MQTT connection demo for clients.

Supports GraalVM compilation to native executables.

Offers a Spring Boot starter for rapid integration (

mica-mqtt-spring-boot-starter

).

The starter integrates with Prometheus and Grafana for monitoring.

Cluster support via Redis pub/sub (see

mica-mqtt-broker

module).

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 applications.

Changelog

2.2.5 - 2023‑10‑05

✨ MQTT business thread pool now supports custom settings using Java 21 virtual threads.

✨ Updated GitHub Actions to use Java 21 instead of Java 17.

✨ Deprecated

ThreadUtil

(temporarily retained) and switched to

ThreadUtils

from mica‑net.

Custom Business Thread Pool

5.1 Adjusting Business Threads for mica-mqtt Client

Important: The default business thread count for the client is 2 , which is sufficient for most lightweight scenarios.

If your client processes a large volume of messages, has long‑running business logic, or exhibits latency or memory growth, you can increase the thread pool size.

Standard Java configuration:

<code>// Initialize MQTT client
MqttClient client = MqttClient.create()
    .ip("127.0.0.1")
    .port(1883)
    .username("admin")
    .password("******")
    // Set business thread pool; typically cpuCores * 2
    .mqttExecutor(ThreadUtils.getBizExecutor(10))
    .connect();
</code>

Spring Boot starter configuration:

<code>@Configuration(proxyBeanMethods = false)
public class MqttClientCustomizerConfiguration {

    @Bean
    public MqttClientCustomizer mqttClientCustomizer() {
        return creator -> {
            // Set business thread pool; typically cpuCores * 2
            creator.mqttExecutor(ThreadUtils.getBizExecutor(10));
        };
    }
}
</code>

If you are on Java 21 and need to handle massive message volumes, you can use virtual threads:

<code>@Configuration(proxyBeanMethods = false)
public class MqttClientCustomizerConfiguration {

    @Bean
    public MqttClientCustomizer mqttClientCustomizer() {
        return creator -> {
            // Use Java 21 virtual threads for business execution
            creator.mqttExecutor(Executors.newVirtualThreadPerTaskExecutor());
        };
    }
}
</code>

5.2 Configuring mica-mqtt Server

The server’s default business thread count is twice the number of CPU cores (minimum 8). For heavy workloads, consider offloading processing to Kafka or RocketMQ and scaling consumer services.

Documentation & Resources

MQTT fundamentals, mqttx, and mica-mqtt tutorial videos: https://b23.tv/VJ8yc7v

mica-mqtt quick‑start repository: https://gitee.com/596392912/mica-mqtt

BackendJavaOpen-sourceIoTlow latencyMQTTaio
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.