Last active
August 29, 2015 14:05
-
-
Save hiun/350e7061741ddde8aedb to your computer and use it in GitHub Desktop.
Super Simple ZeroMQ request - reply example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Please run in separated file - requester.js AND replier.js. | |
//requester.js | |
var zmq = require('zmq') | |
, sock = zmq.socket('req'); | |
sock.connect('tcp://127.0.0.1:3000'); | |
console.log('Requester bound to port 3000'); | |
setInterval(function () { | |
console.log('sending work'); | |
sock.send('some work'); | |
}, 500); | |
sock.on('message', function (msg) { | |
console.log('%s', msg); | |
}); | |
//replier.js | |
var zmq = require('zmq') | |
, sock = zmq.socket('rep'); | |
sock.bindSync('tcp://127.0.0.1:3000'); | |
console.log('Worker connected to port 3000'); | |
sock.on('message', function(msg){ | |
console.log('%s', msg) | |
sock.send('hello'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment