bundyfx bundyfx - 20 days ago 4x
Node.js Question

nodejs rabbitjs simple pub sub rabbitmq

New to NodeJS and RabbitMQ. I am attempting to do a simple pub and sub and store the output from the sub when it receives a message from pub.


var context = require('rabbit.js').createContext();
var sub = context.socket('SUB');
context.on('ready', function() {
sub.connect('events', function() {



var context = require('rabbit.js').createContext();

var pub = context.socket('PUB')
pub.connect('events', function() {

pub.write(JSON.stringify({welcome: 'rabbit.js'}), 'utf8');


This works fine and I get the stdout message (from sub.pipe(process.stdout)) on the console running the sub.js, However my question is how can I work with this object? Is it possible to store that output into a variable and pass it into another function?


sockets are node streams. So instead of piping them to stdout, you can read from them:

sub.on('data', function(message) { /** Do something with message */ });