Created
May 8, 2013 11:23
-
-
Save Vitsaus/5539837 to your computer and use it in GitHub Desktop.
rabbit.js subscriber and publisher
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
// Subscriber | |
var context = require('rabbit.js').createContext(); | |
context.on('ready', function() { | |
var pub = context.socket('PUB'), sub = context.socket('SUB'); | |
sub.pipe(process.stdout); | |
sub.connect('events'); | |
sub.setEncoding('utf8'); | |
sub.on('events', function(data) { | |
console.log(data); | |
}); | |
}); | |
// Publisher | |
context = require('rabbit.js').createContext(); | |
context.on('ready', function() { | |
var pub = context.socket('PUB'), sub = context.socket('SUB'); | |
sub.pipe(process.stdout); | |
pub.connect('events', function() { | |
setInterval(function() { | |
pub.write('hello world from server', 'utf8'); | |
}, 500); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment