Skip to content

Instantly share code, notes, and snippets.

@revant
Last active June 20, 2024 13:36

Revisions

  1. revant revised this gist Jun 20, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mqtt.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    const mqtt = require("mqtt");
    const client = mqtt.connect("mqtt://event-bus:1883", {
    clientId: "clientId",
    clientId: require('crypto').randomUUID(),
    clean: true,
    connectTimeout: 4000,
    username: 'emqx',
  2. revant revised this gist Jun 18, 2024. 2 changed files with 15 additions and 0 deletions.
    File renamed without changes.
    15 changes: 15 additions & 0 deletions tcp.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    const net = require('net');

    const server = net
    .createServer(socket => {
    socket.on('data', data => {
    console.log(data.toString());
    });
    })
    .on('error', err => {
    throw err;
    });

    server.listen(8000, '0.0.0.0', undefined, () => {
    console.log('TCP server is listening on 0.0.0.0:8000');
    });
  3. revant created this gist Jun 13, 2024.
    17 changes: 17 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    const mqtt = require("mqtt");
    const client = mqtt.connect("mqtt://event-bus:1883", {
    clientId: "clientId",
    clean: true,
    connectTimeout: 4000,
    username: 'emqx',
    password: 'public',
    reconnectPeriod: 1000,
    });
    client.on('connect', () => {
    console.log('Connected');
    client.subscribe("+", () => {
    client.on('message', (topic, message) => {
    console.log(`Received message "${message.toString()}" on topic "${topic}"`)
    })
    });
    })