Skip to content

Commit 6c14d3a

Browse files
committed
docs(mica-mqtt): 更新 opencode AGENTS.md
1 parent 907d972 commit 6c14d3a

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

AGENTS.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@
1111

1212
- **Language**: Java 8 (`<java.version>1.8</java.version>`).
1313
- **Build Tool**: Maven 3.x.
14-
- **Project Structure**: Multi-module Maven project (`mica-mqtt-client`, `mica-mqtt-server`, `mica-mqtt-codec`, `mica-mqtt-common`, `starter`).
14+
- **Project Structure**: Multi-module Maven project.
15+
16+
### Modules
17+
18+
| Module | Description |
19+
|--------|-------------|
20+
| `mica-mqtt-codec` | MQTT protocol codec |
21+
| `mica-mqtt-common` | Common utilities and models |
22+
| `mica-mqtt-core` | Core server/client interfaces |
23+
| `mica-mqtt-server` | MQTT broker implementation |
24+
| `mica-mqtt-client` | MQTT client implementation |
25+
| `mica-mqtt-broker` | Enhanced broker with cluster support (t-io based) |
26+
| `starter` | Spring Boot, Solon, JFinal integrations |
27+
| `example` | Usage examples |
1528

1629
### Key Commands
1730

@@ -23,6 +36,7 @@
2336
| **Run Single Test Method** | `mvn -Dtest=TargetTestClass#methodName test` |
2437
| **Compile Only** | `mvn compile` |
2538
| **Package** | `mvn package -DskipTests` |
39+
| **Run Tests in Specific Module** | `cd mica-mqtt-broker && mvn test` |
2640

2741
> **Note**: Always run tests after modifications to ensure no regressions.
2842
@@ -40,7 +54,7 @@
4054
- **Packages**: `lowercase` (e.g., `org.dromara.mica.mqtt.core`).
4155

4256
### Lombok Usage
43-
- **Core Modules** (`mica-mqtt-server`, `mica-mqtt-client`, `mica-mqtt-common`, `mica-mqtt-codec`):
57+
- **Core Modules** (`mica-mqtt-server`, `mica-mqtt-client`, `mica-mqtt-common`, `mica-mqtt-codec`, `mica-mqtt-broker`):
4458
- **DO NOT USE LOMBOK**.
4559
- Manually implement `getters`, `setters`, `equals`, `hashCode`, `toString`, and `constructors`.
4660
- Use the Builder pattern manually if complex object creation is needed (see `MqttWillMessage`).
@@ -71,13 +85,35 @@ All new Java files must include the Apache License 2.0 header:
7185
### Logging
7286
- Use **SLF4J** for logging.
7387
- `private static final Logger logger = LoggerFactory.getLogger(ClassName.class);`
88+
- Use appropriate log levels: `debug` for verbose info, `info` for important events, `warn/error` for issues.
89+
- Avoid excessive `info` logging in high-frequency code paths (e.g., message handling).
7490

7591
### Imports
7692
- Avoid wildcard imports (`import java.util.*;`).
77-
- Group imports:
93+
- Group imports in this order:
7894
1. Project specific imports (`org.dromara...`)
7995
2. Third-party libraries (`org.slf4j...`, `org.tio...`)
8096
3. Standard Java (`java...`, `javax...`)
97+
- Use import statements instead of fully qualified class names in code.
98+
99+
### Error Handling
100+
- Use specific exception types rather than generic `Exception`.
101+
- Log exceptions with appropriate context before rethrowing or handling.
102+
- Avoid swallowing exceptions silently unless explicitly intended.
103+
- Example:
104+
```java
105+
try {
106+
// code
107+
} catch (IOException e) {
108+
logger.error("Failed to process message from node: {}", nodeId, e);
109+
return;
110+
}
111+
```
112+
113+
### Types
114+
- Use primitive types where possible for performance.
115+
- Use `List`, `Map`, `Set` interfaces rather than concrete implementations in method signatures.
116+
- Initialize collections with appropriate implementations (e.g., `ArrayList`, `HashMap`, `HashSet`).
81117

82118
## 3. Architecture & Patterns
83119

@@ -87,16 +123,27 @@ All new Java files must include the Apache License 2.0 header:
87123
- **Design Patterns**:
88124
- **Builder**: Used for complex configuration/message objects (e.g., `MqttPublishMessage.builder()`).
89125
- **Listener**: Heavily used for events (`MqttProtocolListener`, `IMqttMessageListener`).
126+
- **Decorator**: Used in `mica-mqtt-broker` for session management (`ClusterMqttSessionManager` wraps `IMqttSessionManager`).
127+
128+
### Cluster Module (mica-mqtt-broker)
129+
- Built on t-io cluster for node-to-node communication.
130+
- Uses `MqttBroker.create()` as entry point for cluster brokers.
131+
- Fluent API for configuration (`MqttClusterConfig.enabled(true).clusterPort(9001)`).
132+
- Cluster messages inherit from `ClusterMessage` base class.
133+
- Session state is synchronized across nodes via `ClusterMqttSessionManager`.
90134

91135
## 4. Testing
92136

93-
- Write unit tests for new logic using JUnit.
137+
- Write unit tests for new logic using JUnit (Jupiter).
94138
- Place tests in the `src/test/java` directory corresponding to the package structure.
95139
- Mock external dependencies where possible to keep tests fast.
140+
- Cluster integration tests may have Windows-specific cleanup issues with t-io; focus on test assertions passing.
96141

97142
## 5. Agent Behavior Rules
98143

99144
- **No Assumptions**: Always verify file existence and content before editing.
100145
- **Minimal Changes**: Only modify what is necessary to fulfill the request.
101146
- **Preserve Style**: If you see a file using a specific style (even if it contradicts general rules), follow the file's local style (except for clearly erroneous logic).
102147
- **Safety**: Do not commit secrets or breaking changes without user confirmation.
148+
- **Verification**: After making changes, always run `mvn compile` to verify the code compiles.
149+
- **Testing**: Run relevant tests after modifications to ensure no regressions.

0 commit comments

Comments
 (0)