ZeroMQ (zmq) Publisher-Subscriber

Date: 2018-07-14
const zmq = require('zeromq');
const address = 'tcp://127.0.0.1:12345';

let publisher = zmq.socket('pub');

publisher.bind(address, (err) => {
    if (err) {
        console.log(err);
    } else {
        console.log('Listening on 5563…');
    }
});

setInterval(() => {
    let n = Math.ceil(Math.random() * 50) - 10;
    publisher.send(["weather", n]);
    publisher.send(["money", n * 50]);
}, 20);
const zmq = require('zeromq');
const address = 'tcp://127.0.0.1:12345';

var subscriber = zmq.socket('sub');

subscriber.on('message', (...args) => {
    console.log('received', args.map((a) => a.toString()));
});

subscriber.connect(address);
subscriber.subscribe('weather');
subscriber.subscribe('money');

 

11640cookie-checkZeroMQ (zmq) Publisher-Subscriber