omgkit 2.12.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -12
- package/package.json +2 -2
- package/plugin/agents/api-designer.md +5 -0
- package/plugin/agents/architect.md +8 -0
- package/plugin/agents/brainstormer.md +4 -0
- package/plugin/agents/cicd-manager.md +6 -0
- package/plugin/agents/code-reviewer.md +6 -0
- package/plugin/agents/copywriter.md +2 -0
- package/plugin/agents/data-engineer.md +255 -0
- package/plugin/agents/database-admin.md +10 -0
- package/plugin/agents/debugger.md +10 -0
- package/plugin/agents/devsecops.md +314 -0
- package/plugin/agents/docs-manager.md +4 -0
- package/plugin/agents/domain-decomposer.md +181 -0
- package/plugin/agents/embedded-systems.md +397 -0
- package/plugin/agents/fullstack-developer.md +12 -0
- package/plugin/agents/game-systems-designer.md +375 -0
- package/plugin/agents/git-manager.md +10 -0
- package/plugin/agents/journal-writer.md +2 -0
- package/plugin/agents/ml-engineer.md +284 -0
- package/plugin/agents/observability-engineer.md +353 -0
- package/plugin/agents/oracle.md +9 -0
- package/plugin/agents/performance-engineer.md +290 -0
- package/plugin/agents/pipeline-architect.md +6 -0
- package/plugin/agents/planner.md +12 -0
- package/plugin/agents/platform-engineer.md +325 -0
- package/plugin/agents/project-manager.md +3 -0
- package/plugin/agents/researcher.md +5 -0
- package/plugin/agents/scientific-computing.md +426 -0
- package/plugin/agents/scout.md +3 -0
- package/plugin/agents/security-auditor.md +7 -0
- package/plugin/agents/sprint-master.md +17 -0
- package/plugin/agents/tester.md +10 -0
- package/plugin/agents/ui-ux-designer.md +12 -0
- package/plugin/agents/vulnerability-scanner.md +6 -0
- package/plugin/commands/data/pipeline.md +47 -0
- package/plugin/commands/data/quality.md +49 -0
- package/plugin/commands/domain/analyze.md +34 -0
- package/plugin/commands/domain/map.md +41 -0
- package/plugin/commands/game/balance.md +56 -0
- package/plugin/commands/game/optimize.md +62 -0
- package/plugin/commands/iot/provision.md +58 -0
- package/plugin/commands/ml/evaluate.md +47 -0
- package/plugin/commands/ml/train.md +48 -0
- package/plugin/commands/perf/benchmark.md +54 -0
- package/plugin/commands/perf/profile.md +49 -0
- package/plugin/commands/platform/blueprint.md +56 -0
- package/plugin/commands/security/audit.md +54 -0
- package/plugin/commands/security/scan.md +55 -0
- package/plugin/commands/sre/dashboard.md +53 -0
- package/plugin/registry.yaml +711 -0
- package/plugin/skills/ai-ml/experiment-tracking/SKILL.md +338 -0
- package/plugin/skills/ai-ml/feature-stores/SKILL.md +340 -0
- package/plugin/skills/ai-ml/llm-ops/SKILL.md +454 -0
- package/plugin/skills/ai-ml/ml-pipelines/SKILL.md +390 -0
- package/plugin/skills/ai-ml/model-monitoring/SKILL.md +398 -0
- package/plugin/skills/ai-ml/model-serving/SKILL.md +386 -0
- package/plugin/skills/event-driven/cqrs-patterns/SKILL.md +348 -0
- package/plugin/skills/event-driven/event-sourcing/SKILL.md +334 -0
- package/plugin/skills/event-driven/kafka-deep/SKILL.md +252 -0
- package/plugin/skills/event-driven/saga-orchestration/SKILL.md +335 -0
- package/plugin/skills/event-driven/schema-registry/SKILL.md +328 -0
- package/plugin/skills/event-driven/stream-processing/SKILL.md +313 -0
- package/plugin/skills/game/game-audio/SKILL.md +446 -0
- package/plugin/skills/game/game-networking/SKILL.md +490 -0
- package/plugin/skills/game/godot-patterns/SKILL.md +413 -0
- package/plugin/skills/game/shader-programming/SKILL.md +492 -0
- package/plugin/skills/game/unity-patterns/SKILL.md +488 -0
- package/plugin/skills/iot/device-provisioning/SKILL.md +405 -0
- package/plugin/skills/iot/edge-computing/SKILL.md +369 -0
- package/plugin/skills/iot/industrial-protocols/SKILL.md +438 -0
- package/plugin/skills/iot/mqtt-deep/SKILL.md +418 -0
- package/plugin/skills/iot/ota-updates/SKILL.md +426 -0
- package/plugin/skills/microservices/api-gateway-patterns/SKILL.md +201 -0
- package/plugin/skills/microservices/circuit-breaker-patterns/SKILL.md +246 -0
- package/plugin/skills/microservices/contract-testing/SKILL.md +284 -0
- package/plugin/skills/microservices/distributed-tracing/SKILL.md +246 -0
- package/plugin/skills/microservices/service-discovery/SKILL.md +304 -0
- package/plugin/skills/microservices/service-mesh/SKILL.md +181 -0
- package/plugin/skills/mobile-advanced/mobile-ci-cd/SKILL.md +407 -0
- package/plugin/skills/mobile-advanced/mobile-security/SKILL.md +403 -0
- package/plugin/skills/mobile-advanced/offline-first/SKILL.md +473 -0
- package/plugin/skills/mobile-advanced/push-notifications/SKILL.md +494 -0
- package/plugin/skills/mobile-advanced/react-native-deep/SKILL.md +374 -0
- package/plugin/skills/simulation/numerical-methods/SKILL.md +434 -0
- package/plugin/skills/simulation/parallel-computing/SKILL.md +382 -0
- package/plugin/skills/simulation/physics-engines/SKILL.md +377 -0
- package/plugin/skills/simulation/validation-verification/SKILL.md +479 -0
- package/plugin/skills/simulation/visualization-scientific/SKILL.md +365 -0
- package/plugin/templates/autonomous/archetypes/event-driven-app.yaml +460 -0
- package/plugin/templates/autonomous/archetypes/microservices-app.yaml +431 -0
- package/plugin/templates/autonomous/state-schema.yaml +1 -1
- package/plugin/workflows/ai-engineering/agent-development.md +3 -3
- package/plugin/workflows/ai-engineering/fine-tuning.md +3 -3
- package/plugin/workflows/ai-engineering/model-evaluation.md +3 -3
- package/plugin/workflows/ai-engineering/prompt-engineering.md +2 -2
- package/plugin/workflows/ai-engineering/rag-development.md +4 -4
- package/plugin/workflows/ai-ml/data-pipeline.md +188 -0
- package/plugin/workflows/ai-ml/experiment-cycle.md +203 -0
- package/plugin/workflows/ai-ml/feature-engineering.md +208 -0
- package/plugin/workflows/ai-ml/model-deployment.md +199 -0
- package/plugin/workflows/ai-ml/monitoring-setup.md +227 -0
- package/plugin/workflows/api/api-design.md +1 -1
- package/plugin/workflows/api/api-testing.md +2 -2
- package/plugin/workflows/content/technical-docs.md +1 -1
- package/plugin/workflows/database/migration.md +1 -1
- package/plugin/workflows/database/optimization.md +1 -1
- package/plugin/workflows/database/schema-design.md +3 -3
- package/plugin/workflows/development/bug-fix.md +3 -3
- package/plugin/workflows/development/code-review.md +2 -1
- package/plugin/workflows/development/feature.md +3 -3
- package/plugin/workflows/development/refactor.md +2 -2
- package/plugin/workflows/event-driven/consumer-groups.md +190 -0
- package/plugin/workflows/event-driven/event-storming.md +172 -0
- package/plugin/workflows/event-driven/replay-testing.md +186 -0
- package/plugin/workflows/event-driven/saga-implementation.md +206 -0
- package/plugin/workflows/event-driven/schema-evolution.md +173 -0
- package/plugin/workflows/fullstack/authentication.md +4 -4
- package/plugin/workflows/fullstack/full-feature.md +4 -4
- package/plugin/workflows/game-dev/content-pipeline.md +218 -0
- package/plugin/workflows/game-dev/platform-submission.md +263 -0
- package/plugin/workflows/game-dev/playtesting.md +237 -0
- package/plugin/workflows/game-dev/prototype-to-production.md +205 -0
- package/plugin/workflows/microservices/contract-first.md +151 -0
- package/plugin/workflows/microservices/distributed-tracing.md +166 -0
- package/plugin/workflows/microservices/domain-decomposition.md +123 -0
- package/plugin/workflows/microservices/integration-testing.md +149 -0
- package/plugin/workflows/microservices/service-mesh-setup.md +153 -0
- package/plugin/workflows/microservices/service-scaffolding.md +151 -0
- package/plugin/workflows/omega/1000x-innovation.md +2 -2
- package/plugin/workflows/omega/100x-architecture.md +2 -2
- package/plugin/workflows/omega/10x-improvement.md +2 -2
- package/plugin/workflows/quality/performance-optimization.md +2 -2
- package/plugin/workflows/research/best-practices.md +1 -1
- package/plugin/workflows/research/technology-research.md +1 -1
- package/plugin/workflows/security/penetration-testing.md +3 -3
- package/plugin/workflows/security/security-audit.md +3 -3
- package/plugin/workflows/sprint/sprint-execution.md +2 -2
- package/plugin/workflows/sprint/sprint-retrospective.md +1 -1
- package/plugin/workflows/sprint/sprint-setup.md +1 -1
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
# MQTT Deep
|
|
2
|
+
|
|
3
|
+
Advanced MQTT patterns including QoS levels, retained messages, last will, topic design, and broker clustering.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
MQTT (Message Queuing Telemetry Transport) is a lightweight publish-subscribe protocol designed for constrained devices and unreliable networks.
|
|
8
|
+
|
|
9
|
+
## Core Concepts
|
|
10
|
+
|
|
11
|
+
### Quality of Service (QoS)
|
|
12
|
+
- **QoS 0**: At most once (fire and forget)
|
|
13
|
+
- **QoS 1**: At least once (acknowledged)
|
|
14
|
+
- **QoS 2**: Exactly once (4-step handshake)
|
|
15
|
+
|
|
16
|
+
### Key Features
|
|
17
|
+
- **Retained Messages**: Last known value for new subscribers
|
|
18
|
+
- **Last Will and Testament (LWT)**: Disconnection notification
|
|
19
|
+
- **Clean Session**: Session state persistence
|
|
20
|
+
- **Keep Alive**: Connection heartbeat
|
|
21
|
+
|
|
22
|
+
## Topic Design
|
|
23
|
+
|
|
24
|
+
### Hierarchical Structure
|
|
25
|
+
```
|
|
26
|
+
# Good topic design
|
|
27
|
+
home/living-room/temperature
|
|
28
|
+
home/living-room/humidity
|
|
29
|
+
home/bedroom/temperature
|
|
30
|
+
factory/line-1/machine-001/status
|
|
31
|
+
factory/line-1/machine-001/metrics/temperature
|
|
32
|
+
factory/line-1/machine-001/metrics/vibration
|
|
33
|
+
|
|
34
|
+
# Topic wildcards
|
|
35
|
+
home/+/temperature # Single level: matches any room
|
|
36
|
+
home/# # Multi level: matches all under home
|
|
37
|
+
factory/+/+/status # Status of all machines in all lines
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Topic Best Practices
|
|
41
|
+
```
|
|
42
|
+
# Use lowercase
|
|
43
|
+
sensors/temperature ✓
|
|
44
|
+
Sensors/Temperature ✗
|
|
45
|
+
|
|
46
|
+
# Use hyphens for spaces
|
|
47
|
+
living-room ✓
|
|
48
|
+
living_room ✗
|
|
49
|
+
livingRoom ✗
|
|
50
|
+
|
|
51
|
+
# Include device/location context
|
|
52
|
+
{environment}/{location}/{device}/{metric}
|
|
53
|
+
prod/building-a/sensor-001/temperature
|
|
54
|
+
|
|
55
|
+
# Command topics (bidirectional)
|
|
56
|
+
devices/{device-id}/commands # Commands to device
|
|
57
|
+
devices/{device-id}/commands/ack # Acknowledgments
|
|
58
|
+
devices/{device-id}/telemetry # Data from device
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Client Implementation
|
|
62
|
+
|
|
63
|
+
### Node.js Client
|
|
64
|
+
```typescript
|
|
65
|
+
import mqtt, { MqttClient, IClientOptions } from 'mqtt';
|
|
66
|
+
|
|
67
|
+
interface DeviceMessage {
|
|
68
|
+
deviceId: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
data: Record<string, any>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
class MQTTService {
|
|
74
|
+
private client: MqttClient;
|
|
75
|
+
private readonly options: IClientOptions;
|
|
76
|
+
|
|
77
|
+
constructor(brokerUrl: string, clientId: string) {
|
|
78
|
+
this.options = {
|
|
79
|
+
clientId,
|
|
80
|
+
clean: false, // Persistent session
|
|
81
|
+
connectTimeout: 30000,
|
|
82
|
+
reconnectPeriod: 5000,
|
|
83
|
+
keepalive: 60,
|
|
84
|
+
// Authentication
|
|
85
|
+
username: process.env.MQTT_USER,
|
|
86
|
+
password: process.env.MQTT_PASS,
|
|
87
|
+
// TLS
|
|
88
|
+
protocol: 'mqtts',
|
|
89
|
+
rejectUnauthorized: true,
|
|
90
|
+
// Last Will and Testament
|
|
91
|
+
will: {
|
|
92
|
+
topic: `devices/${clientId}/status`,
|
|
93
|
+
payload: JSON.stringify({ status: 'offline', timestamp: Date.now() }),
|
|
94
|
+
qos: 1,
|
|
95
|
+
retain: true
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
this.client = mqtt.connect(brokerUrl, this.options);
|
|
100
|
+
this.setupHandlers();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private setupHandlers(): void {
|
|
104
|
+
this.client.on('connect', () => {
|
|
105
|
+
console.log('Connected to MQTT broker');
|
|
106
|
+
// Publish online status (retained)
|
|
107
|
+
this.publish(
|
|
108
|
+
`devices/${this.options.clientId}/status`,
|
|
109
|
+
{ status: 'online', timestamp: Date.now() },
|
|
110
|
+
{ qos: 1, retain: true }
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
this.client.on('error', (error) => {
|
|
115
|
+
console.error('MQTT error:', error);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
this.client.on('offline', () => {
|
|
119
|
+
console.log('MQTT client offline');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
this.client.on('reconnect', () => {
|
|
123
|
+
console.log('MQTT reconnecting...');
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
subscribe(
|
|
128
|
+
topic: string,
|
|
129
|
+
handler: (topic: string, message: any) => void,
|
|
130
|
+
qos: 0 | 1 | 2 = 1
|
|
131
|
+
): void {
|
|
132
|
+
this.client.subscribe(topic, { qos }, (err) => {
|
|
133
|
+
if (err) {
|
|
134
|
+
console.error(`Subscribe error for ${topic}:`, err);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
console.log(`Subscribed to ${topic}`);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
this.client.on('message', (receivedTopic, payload) => {
|
|
141
|
+
if (this.topicMatches(topic, receivedTopic)) {
|
|
142
|
+
try {
|
|
143
|
+
const message = JSON.parse(payload.toString());
|
|
144
|
+
handler(receivedTopic, message);
|
|
145
|
+
} catch {
|
|
146
|
+
handler(receivedTopic, payload.toString());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
publish(
|
|
153
|
+
topic: string,
|
|
154
|
+
message: any,
|
|
155
|
+
options: { qos?: 0 | 1 | 2; retain?: boolean } = {}
|
|
156
|
+
): Promise<void> {
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
const payload = typeof message === 'string'
|
|
159
|
+
? message
|
|
160
|
+
: JSON.stringify(message);
|
|
161
|
+
|
|
162
|
+
this.client.publish(
|
|
163
|
+
topic,
|
|
164
|
+
payload,
|
|
165
|
+
{ qos: options.qos || 1, retain: options.retain || false },
|
|
166
|
+
(err) => {
|
|
167
|
+
if (err) reject(err);
|
|
168
|
+
else resolve();
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private topicMatches(pattern: string, topic: string): boolean {
|
|
175
|
+
const patternParts = pattern.split('/');
|
|
176
|
+
const topicParts = topic.split('/');
|
|
177
|
+
|
|
178
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
179
|
+
if (patternParts[i] === '#') return true;
|
|
180
|
+
if (patternParts[i] === '+') continue;
|
|
181
|
+
if (patternParts[i] !== topicParts[i]) return false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return patternParts.length === topicParts.length;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async disconnect(): Promise<void> {
|
|
188
|
+
// Publish offline status before disconnecting
|
|
189
|
+
await this.publish(
|
|
190
|
+
`devices/${this.options.clientId}/status`,
|
|
191
|
+
{ status: 'offline', timestamp: Date.now() },
|
|
192
|
+
{ qos: 1, retain: true }
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
return new Promise((resolve) => {
|
|
196
|
+
this.client.end(false, {}, resolve);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Embedded Client (ESP32/Arduino)
|
|
203
|
+
```cpp
|
|
204
|
+
#include <WiFi.h>
|
|
205
|
+
#include <PubSubClient.h>
|
|
206
|
+
#include <ArduinoJson.h>
|
|
207
|
+
|
|
208
|
+
const char* WIFI_SSID = "your-ssid";
|
|
209
|
+
const char* WIFI_PASS = "your-password";
|
|
210
|
+
const char* MQTT_SERVER = "mqtt.example.com";
|
|
211
|
+
const int MQTT_PORT = 8883;
|
|
212
|
+
const char* MQTT_USER = "device";
|
|
213
|
+
const char* MQTT_PASS = "password";
|
|
214
|
+
const char* DEVICE_ID = "sensor-001";
|
|
215
|
+
|
|
216
|
+
WiFiClientSecure espClient;
|
|
217
|
+
PubSubClient mqtt(espClient);
|
|
218
|
+
|
|
219
|
+
void callback(char* topic, byte* payload, unsigned int length) {
|
|
220
|
+
StaticJsonDocument<256> doc;
|
|
221
|
+
DeserializationError err = deserializeJson(doc, payload, length);
|
|
222
|
+
|
|
223
|
+
if (err) {
|
|
224
|
+
Serial.println("JSON parse error");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const char* command = doc["command"];
|
|
229
|
+
if (strcmp(command, "reboot") == 0) {
|
|
230
|
+
ESP.restart();
|
|
231
|
+
} else if (strcmp(command, "config") == 0) {
|
|
232
|
+
// Apply configuration
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
void reconnect() {
|
|
237
|
+
while (!mqtt.connected()) {
|
|
238
|
+
String clientId = String(DEVICE_ID);
|
|
239
|
+
|
|
240
|
+
// LWT configuration
|
|
241
|
+
String lwt_topic = "devices/" + clientId + "/status";
|
|
242
|
+
String lwt_payload = "{\"status\":\"offline\"}";
|
|
243
|
+
|
|
244
|
+
if (mqtt.connect(
|
|
245
|
+
clientId.c_str(),
|
|
246
|
+
MQTT_USER,
|
|
247
|
+
MQTT_PASS,
|
|
248
|
+
lwt_topic.c_str(),
|
|
249
|
+
1, // QoS 1
|
|
250
|
+
true, // Retain
|
|
251
|
+
lwt_payload.c_str()
|
|
252
|
+
)) {
|
|
253
|
+
Serial.println("MQTT connected");
|
|
254
|
+
|
|
255
|
+
// Publish online status
|
|
256
|
+
String status_topic = "devices/" + clientId + "/status";
|
|
257
|
+
mqtt.publish(status_topic.c_str(), "{\"status\":\"online\"}", true);
|
|
258
|
+
|
|
259
|
+
// Subscribe to commands
|
|
260
|
+
String cmd_topic = "devices/" + clientId + "/commands";
|
|
261
|
+
mqtt.subscribe(cmd_topic.c_str(), 1);
|
|
262
|
+
} else {
|
|
263
|
+
delay(5000);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
void publishTelemetry(float temperature, float humidity) {
|
|
269
|
+
StaticJsonDocument<256> doc;
|
|
270
|
+
doc["device_id"] = DEVICE_ID;
|
|
271
|
+
doc["timestamp"] = millis();
|
|
272
|
+
doc["temperature"] = temperature;
|
|
273
|
+
doc["humidity"] = humidity;
|
|
274
|
+
|
|
275
|
+
char buffer[256];
|
|
276
|
+
serializeJson(doc, buffer);
|
|
277
|
+
|
|
278
|
+
String topic = String("devices/") + DEVICE_ID + "/telemetry";
|
|
279
|
+
mqtt.publish(topic.c_str(), buffer, false);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
void setup() {
|
|
283
|
+
Serial.begin(115200);
|
|
284
|
+
|
|
285
|
+
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
|
286
|
+
while (WiFi.status() != WL_CONNECTED) {
|
|
287
|
+
delay(500);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
espClient.setCACert(root_ca);
|
|
291
|
+
mqtt.setServer(MQTT_SERVER, MQTT_PORT);
|
|
292
|
+
mqtt.setCallback(callback);
|
|
293
|
+
mqtt.setBufferSize(512);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
void loop() {
|
|
297
|
+
if (!mqtt.connected()) {
|
|
298
|
+
reconnect();
|
|
299
|
+
}
|
|
300
|
+
mqtt.loop();
|
|
301
|
+
|
|
302
|
+
static unsigned long lastPublish = 0;
|
|
303
|
+
if (millis() - lastPublish > 30000) {
|
|
304
|
+
publishTelemetry(readTemperature(), readHumidity());
|
|
305
|
+
lastPublish = millis();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Broker Configuration
|
|
311
|
+
|
|
312
|
+
### Mosquitto Config
|
|
313
|
+
```conf
|
|
314
|
+
# mosquitto.conf
|
|
315
|
+
listener 1883
|
|
316
|
+
listener 8883
|
|
317
|
+
|
|
318
|
+
# TLS
|
|
319
|
+
cafile /etc/mosquitto/certs/ca.crt
|
|
320
|
+
certfile /etc/mosquitto/certs/server.crt
|
|
321
|
+
keyfile /etc/mosquitto/certs/server.key
|
|
322
|
+
require_certificate false
|
|
323
|
+
|
|
324
|
+
# Authentication
|
|
325
|
+
password_file /etc/mosquitto/passwd
|
|
326
|
+
allow_anonymous false
|
|
327
|
+
|
|
328
|
+
# ACL
|
|
329
|
+
acl_file /etc/mosquitto/acl
|
|
330
|
+
|
|
331
|
+
# Persistence
|
|
332
|
+
persistence true
|
|
333
|
+
persistence_location /var/lib/mosquitto/
|
|
334
|
+
|
|
335
|
+
# Logging
|
|
336
|
+
log_dest file /var/log/mosquitto/mosquitto.log
|
|
337
|
+
log_type all
|
|
338
|
+
|
|
339
|
+
# Limits
|
|
340
|
+
max_connections 1000
|
|
341
|
+
max_inflight_messages 20
|
|
342
|
+
max_queued_messages 1000
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### ACL Configuration
|
|
346
|
+
```
|
|
347
|
+
# acl
|
|
348
|
+
# Device access
|
|
349
|
+
user device-%c
|
|
350
|
+
topic read devices/%c/commands
|
|
351
|
+
topic write devices/%c/telemetry
|
|
352
|
+
topic write devices/%c/status
|
|
353
|
+
|
|
354
|
+
# Admin access
|
|
355
|
+
user admin
|
|
356
|
+
topic readwrite #
|
|
357
|
+
|
|
358
|
+
# Service access
|
|
359
|
+
user telemetry-service
|
|
360
|
+
topic read devices/+/telemetry
|
|
361
|
+
topic read devices/+/status
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## MQTT 5 Features
|
|
365
|
+
|
|
366
|
+
### Request/Response
|
|
367
|
+
```typescript
|
|
368
|
+
// Request (using correlation data)
|
|
369
|
+
const correlationId = uuid();
|
|
370
|
+
|
|
371
|
+
await client.publish('devices/sensor-001/commands', {
|
|
372
|
+
command: 'get-config',
|
|
373
|
+
correlationId
|
|
374
|
+
}, {
|
|
375
|
+
responseTopic: 'responses/' + clientId,
|
|
376
|
+
correlationData: Buffer.from(correlationId)
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// Response handling
|
|
380
|
+
client.subscribe('responses/' + clientId);
|
|
381
|
+
client.on('message', (topic, payload, packet) => {
|
|
382
|
+
if (packet.properties?.correlationData) {
|
|
383
|
+
const corrId = packet.properties.correlationData.toString();
|
|
384
|
+
// Match with request
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Best Practices
|
|
390
|
+
|
|
391
|
+
1. **Use QoS Appropriately**: QoS 0 for telemetry, QoS 1 for commands
|
|
392
|
+
2. **Implement LWT**: Detect device disconnections
|
|
393
|
+
3. **Use Retained Messages**: For device status
|
|
394
|
+
4. **Topic Hierarchy**: Logical, consistent structure
|
|
395
|
+
5. **Connection Recovery**: Handle reconnections gracefully
|
|
396
|
+
|
|
397
|
+
## Anti-Patterns
|
|
398
|
+
|
|
399
|
+
- Publishing to # wildcard
|
|
400
|
+
- Very deep topic hierarchies
|
|
401
|
+
- Large payloads (>256KB)
|
|
402
|
+
- Too frequent publishes
|
|
403
|
+
- Not implementing LWT
|
|
404
|
+
|
|
405
|
+
## When to Use
|
|
406
|
+
|
|
407
|
+
- IoT device communication
|
|
408
|
+
- Real-time messaging
|
|
409
|
+
- Resource-constrained devices
|
|
410
|
+
- Unreliable networks
|
|
411
|
+
- Pub/sub patterns
|
|
412
|
+
|
|
413
|
+
## When NOT to Use
|
|
414
|
+
|
|
415
|
+
- Request/response dominant (use HTTP)
|
|
416
|
+
- Large file transfers
|
|
417
|
+
- Strict ordering requirements
|
|
418
|
+
- Database replication
|