Created
August 30, 2012 13:17
-
-
Save madhums/3528343 to your computer and use it in GitHub Desktop.
zmq - passing objects to workers
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
var zmq = require('zmq') | |
, sock = zmq.socket('push'); | |
sock.bindSync('tcp://127.0.0.1:3000'); | |
console.log('Producer bound to port 3000'); | |
setTimeout(function(){ | |
console.log('sending work'); | |
var data = { | |
service: 'github' | |
, action: 'add' | |
, resourceType: 'user' | |
} | |
, object = JSON.stringify(data) | |
// sending objects | |
sock.send(object); | |
}, 500); |
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
var zmq = require('zmq') | |
, sock = zmq.socket('pull'); | |
sock.connect('tcp://127.0.0.1:3000'); | |
console.log('Worker connected to port 3000'); | |
sock.on('message', function(msg){ | |
var data = JSON.parse(msg.toString()) | |
console.log(data) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment