-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ts
41 lines (33 loc) · 916 Bytes
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Aedes from "aedes";
import * as mqtt from "mqtt";
import { createServer } from "net";
import { tmpdir } from "os";
import { join } from "path";
import { Manager } from "./src";
async function setup(): Promise<void> {
const port = 1883;
const broker = new Aedes();
const server = createServer(broker.handle);
server.listen(port, () => {
console.log("server listening on port", port);
});
const tmpDir = join(tmpdir(), "mqtt-jsonl-store-test");
const manager = new Manager(tmpDir);
await manager.open();
const client = mqtt.connect({
port,
incomingStore: manager.incoming,
outgoingStore: manager.outgoing,
});
client.on("connect", () => {
console.log("client connected");
});
client.publish("hello", "world", { qos: 1 });
broker.on("client", (c) => {
console.log("client", c.id);
});
broker.on("publish", (packet, c) => {
console.log("publish", packet, c);
});
}
setup();