mica-mqtt
CLAUDE.md495 starsChanged 7 months agoApache-2.0View on GitHub
mica-mqtt is a high-performance, low-latency MQTT IoT component for Java 8+, maintained by the Dromara organization. It provides both client and server (broker) implementations supporting MQTT v3.1, v3.1.1, and v5.0 protocols. Key Features: - Lightweight core (only 500KB) - Built on t-io async networking framework - WebSocket MQTT sub-protocol support (compatible with mqtt.js) - HTTP REST API for server management - Shared subscriptions and queue subscriptions - Client/Server support for Spring Boot, Solon, and JFinal - GraalVM native compilation support…
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this CLAUDE.md into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 123
Use ChannelContext for per-connection state
- Very specific: line 148
Note: If publishing to /topic/test (leading slash), subscribe to $share/group1//topic/test (double slash).
- Distinctive: line 191
Use TABS for indentation (not spaces)
- Distinctive: line 192
Always include Apache License 2.0 header in new files
- Very specific: line 193
Use SLF4J for logging: private static final Logger logger = LoggerFactory.getLogger(ClassName.class).
- Very specific: line 218
Run tests after modifications: mvn test
≈ “Common” is an estimate: at least 1 in 5 of the 27,641 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
mica-mqtt is a high-performance, low-latency MQTT IoT component for Java 8+, maintained by the Dromara organization. It provides both client and server (broker) implementations supporting MQTT v3.1, v3.1.1, and v5.0 protocols.
Key Features:
- Lightweight core (only 500KB)
- Built on t-io async networking framework
- WebSocket MQTT sub-protocol support (compatible with mqtt.js)
- HTTP REST API for server management
- Shared subscriptions and queue subscriptions
- Client/Server support for Spring Boot, Solon, and JFinal
- GraalVM native compilation support
- Clustering via
mica-mqtt-brokermodule (t-io cluster for node-to-node communication)
Documentation: https://mica-mqtt.dreamlu.net/guide/ Demo Server: mqtt.dreamlu.net (username: mica, password: mica)
Common Commands
Build & Test
# Full build with tests (includes example module via develop profile)
mvn clean install
# Build without tests
mvn package -DskipTests
# Run all tests
mvn test
# Run specific test class
mvn -Dtest=TopicFilterTypeTest test
# Run specific test method
mvn -Dtest=TopicFilterTypeTest#methodName test
# Compile only
mvn compileModule-Specific Build
# Build mica-mqtt-broker (cluster module, not in develop profile by default)
mvn clean install -pl mica-mqtt-broker -amRelease Commands
# Create snapshot release
mvn clean deploy -P snapshot
# Create production release (includes GPG signing, javadoc)
mvn clean deploy -P releaseArchitecture Overview
Module Structure
mica-mqtt/
├── mica-mqtt-codec # MQTT protocol encoding/decoding (no business logic)
├── mica-mqtt-common # Common utilities, topic filters, message models
├── mica-mqtt-client # MQTT client implementation
├── mica-mqtt-server # MQTT broker/server implementation
├── mica-mqtt-broker # Cluster broker (t-io based, node-to-node communication)
└── starter/ # Framework integrations
├── mica-mqtt-client-spring-boot-starter
├── mica-mqtt-server-spring-boot-starter
├── mica-mqtt-client-solon-plugin
├── mica-mqtt-server-solon-plugin
├── mica-mqtt-client-jfinal-plugin
└── mica-mqtt-server-jfinal-pluginDependency Flow:
client/server→common→codec+mica-net-core(both direct dependencies)broker→server+mica-net-core
Active Profile Modules (develop profile, active by default):
common, client, server, starter, example
Note: mica-mqtt-codec and mica-mqtt-broker are built as transitive dependencies but not as top-level modules in the develop profile.
Core Classes
Client Side:
MqttClient/MqttClientCreator: Main client API with builder patternIMqttClientSession: Session management (subscription tracking, message queuing)DefaultMqttClientProcessor: Message processing pipelineMqttClientAioHandler/MqttClientAioListener: t-io integration layer
Server Side:
MqttServer/MqttServerCreator: Main server API with builder patternMqttServerProcessor: Message routing and deliveryIMqttSessionManager: Client session lifecycle managementMqttMessageStore: Retained messages and will messages storageMqttServerAioHandler/MqttServerAioListener: t-io integration layer
Broker/Cluster Side (mica-mqtt-broker):
MqttBroker: Entry point for cluster brokers (MqttBroker.create())MqttClusterManager: Manages cluster node communicationClusterMqttSessionManager: Session synchronization across nodes (decorator wrappingIMqttSessionManager)ClusterMessageDispatcher: Routes messages across broker instancesBrokerMessage: Base class for cluster messages
Design Patterns
- Builder Pattern:
MqttClient.create(),MqttServer.create(),MqttPublishMessage.builder() - Listener Pattern: Event-driven architecture for connections, messages, subscriptions (
MqttProtocolListener,IMqttMessageListener) - Processor Pattern: Message pipeline with interceptors (
IMqttMessageInterceptor) - Strategy Pattern: Pluggable auth (
IMqttServerAuthHandler), serialization (IMqttSerializer), message dispatching (IMqttMessageDispatcher) - Decorator Pattern:
ClusterMqttSessionManagerwrapsIMqttSessionManagerfor session sync
Thread Safety & Async I/O
- Built on t-io framework - avoid blocking operations in I/O callback threads
- Core classes like
MqttServerandMqttClienthandle concurrent access - Use
ChannelContextfor per-connection state - Session storage uses concurrent data structures (
ConcurrentHashMap)
Protocol Ports (Default)
| Port | Protocol | Purpose |
| 1883 | TCP | Standard MQTT |
| 8883 | TCP SSL | MQTT over TLS |
| 8083 | WebSocket | WebSocket MQTT sub-protocol |
| 8084 | WebSocket SSL | Secure WebSocket MQTT |
| 18083 | HTTP | REST API & MCP interface |
Topic Wildcards
/: Hierarchy separator (e.g.,a/b/c)#: Multi-level wildcard - matches ≥0 levels (e.g.,a/#matchesa/,a/b,a/b/c). Must be last character.+: Single-level wildcard - matches exactly 1 level (e.g.,a/+matchesa/b, nota/b/c). Can combine with#:+/tennis/#
Shared Subscriptions
Two modes for load balancing:
- Queue Subscription:
$queue/topic- Only one subscriber receives each message - Group Subscription:
$share/<group>/topic- One subscriber per group receives each message
Note: If publishing to /topic/test (leading slash), subscribe to $share/group1//topic/test (double slash).
Framework Integration Points
Spring Boot:
- Auto-configuration via
@EnableMqttServer/@EnableMqttClient @MqttClientSubscribefor declarative subscriptionsMqttTemplatefor publishing (if using starter patterns)- Properties:
mqtt.client.*,mqtt.server.*
Solon:
- Plugin-based initialization
- Use
@MqttClientSubscribeannotations - Configuration through
application.yml
JFinal:
- Manual plugin registration in
configPlugin() - Direct API usage via
MqttClient/MqttServer
Clustering & Message Dispatching
The mica-mqtt-broker module provides clustering via t-io cluster for node-to-node communication:
MqttBroker.create()as entry point with fluent API:MqttClusterConfig.enabled(true).clusterPort(9001)- Session state synchronized across nodes via
ClusterMqttSessionManager - Cluster messages inherit from
BrokerMessagebase class - Implement
IMqttMessageDispatcherto route messages across brokers (Redis Pub/Sub, Kafka, RocketMQ)
HTTP API
Server exposes REST API on port 18083 for:
- Publishing messages to clients
- Querying online clients
- Managing subscriptions
Requires one JSON library: Jackson, Fastjson, Fastjson2, Gson, Hutool-json, or Snack3.
See docs/http-api.md for endpoints.
Important Notes
Code Style
- Java 8 compatible code only
- NO Lombok in core modules (
mica-mqtt-client,mica-mqtt-server,mica-mqtt-common,mica-mqtt-codec,mica-mqtt-broker) - Use TABS for indentation (not spaces)
- Always include Apache License 2.0 header in new files
- Use SLF4J for logging:
private static final Logger logger = LoggerFactory.getLogger(ClassName.class);
License Header (required for new files)
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & dreamlu.net).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/Testing
- Tests located in
src/test/javamatching package structure - Run tests after modifications:
mvn test - Mock external dependencies for unit tests
Android Support
Minimum API 26 (Android 8.0). Add to build.gradle:
android {
packagingOptions {
exclude 'META-INF/INDEX.LIST' // Required for mica-mqtt
}
}Memory Optimization
For server deployments handling many connections, use JVM flag: -Xss129k to reduce per-thread stack size.
Version Management
- Uses
${revision}property for version (defined in root pom.xml) - Flatten Maven plugin processes version for publishing
- Current version:
2.6.0 - Main branch for PRs:
master
Module-Specific READMEs
Each module has detailed usage documentation:
mica-mqtt-client/README.md- Client API examplesmica-mqtt-server/README.md- Server configuration examplesmica-mqtt-broker/README.md- Cluster broker configurationstarter/*/README.md- Framework-specific configurationexample/- Working examples for all integrations
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

