To answer the original question, if for some reason you wanted to use Rabbit MQ instead of Sails, the built-in resourceful pubsub , the best thing would be to use rabbit.js .
First npm install rabbit.js .
Then in the Sails project, config / sockets.js (borrowed liberally from rabbit.js socket.io example ):
var context = require('rabbit.js').createContext(); module.exports = { onConnect: function(session, socket) { var pub = context.socket('PUB'); var sub = context.socket('SUB'); socket.on('disconnect', function() { pub.close(); sub.close(); }); // NB we have to adapt between the APIs sub.setEncoding('utf8'); socket.on('message', function(msg) { pub.write(msg, 'utf8'); }); sub.on('data', function(msg) { socket.send(msg); }); sub.connect('chat'); pub.connect('chat'); } }
source share