-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (22 loc) · 973 Bytes
/
index.js
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
import mqtt from 'mqtt';
import { createMqttBroker } from './broker.js';
import { createMqttJsClient } from './mqtt-js.js';
import { createU8MqttClient } from './u8-mqtt.js';
import { createLargePayload } from './create-large-json.js';
import { promisify } from 'util';
const waitFor = promisify(setTimeout);
async function test() {
const broker = await createMqttBroker();
const u8Client = await createU8MqttClient();
const mqttJsClient = await createMqttJsClient();
const publisher = await mqtt.connectAsync('mqtt://localhost:1883');
// publish small payload
console.log('\nPublishing small payload');
await publisher.publishAsync('foo', JSON.stringify({ foo: 'bar' }));
await waitFor(1000);
// publish large payload
console.log('\nPublishing large payload');
await publisher.publishAsync('foo', createLargePayload());
// result - for the first message both clients log the result, for the second message - only MQTT.js logs it
}
test();