Some helpers for simplified use of zeromq.node.
Look at the supported Node and zmq versions here.
$ npm install zmq-toolkit
To start the broker in its own process:
$ npm install -g zmq-toolkit
$ zmqbroker tcp://127.0.0.1:11111 tcp://127.0.0.1:22222
// pubsub proxy that binds to the given XSUB and XPUB sockets
var Broker = require('zmq-toolkit').Broker
, broker = new Broker()
.start('tcp://127.0.0.1:11111', 'tcp://127.0.0.1:22222');
// zeromq based EventEmitter that connects to the zeromq xpub/xsub broker
var ZmqEventEmitter = require('zmq-toolkit').ZmqEventEmitter
, zee = new ZmqEventEmitter()
.start('tcp://127.0.0.1:11111', 'tcp://127.0.0.1:22222')
.on('my-event', function(options) {
console.log(options.foo);
})
.on('my-other-event', function(options) {
console.log(options.foo);
});
setTimeout(function() { // need some time to connect sockets
zee.emit('my-event', {foo: 'bar'});
}, 100);
// connect socket.io sockets to a zeromq xpub/xsub broker
var ZmqEventEmitter = require('zmq-toolkit').ZmqEventEmitter
, zee = new ZmqEventEmitter()
.start('tcp://127.0.0.1:11111', 'tcp://127.0.0.1:22222');
io.sockets.on('connection', function (socket) {
zee.hug(socket);
socket.emit('foo'); // will be forwared to zee
socket.on('bar', function() {
console.log('baz');
});
zee.emit('bar'); // will invoke the websocket's handler for this event
});
// periodically emit a ```heartbeat``` event with arbitrary data to a zeromq xpub/xsub broker
var Heartbeat = require('zmq-toolkit').Heartbeat
, heartbeat = new Heartbeat({name: 'my-app'})
.start('tcp://127.0.0.1:11111', 60000); // connet to xsub socket, emit every 60 seconds