RabbitMQ and Sails.js

I'm having problems using RabbitMQ with my Sails application. I do not know where to place the subscriber code. What I'm trying to do is to create a notification system so that the administrator approves the user data request, and the user control panel will display a notification similar to how Facebook issues a notification. The problem is that, apparently, the subscriber code on my route of the dashboard controller never captures the published message.

Any advice would be greatly appreciated. Currently, the rabbit.js package is used to connect to RabbitMQ.

+6
source share
2 answers

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'); } } 
+5
source

Here's the npm package that implements the RabbitMQ adapter for SailsJS.

0
source

Source: https://habr.com/ru/post/973614/


All Articles