const RabbitMQ = require('env-rmq').RabbitMQ;
const rmq = new RabbitMQ({
uri: 'amqp://user:password@localhost/'
});
rmq.connect().then(() => {
console.log('Ready.');
}).catch(err => {
console.log('Error: ', err);
});
rmq.worker('my-queue-name', function (msg, reject, ack) {
ack();
});
// Assert channel on application loading
rmq.worker('my-queue-name');
// Send task everywhere
rmq.worker('my-queue-name').send({
someField: "Hello world!"
});
rmq.pubsub('my-pub-name', function (msg, reject, ack) {
ack();
});
// Assert channel on application loading
rmq.pubsub('my-pub-name');
rmq.pubsub('my-pub-name').send({
someField: "Hello world!"
});
rmq.rpc('my-function', function (msg, reject, ack) {
ack({
returnValue:"OK!"
});
});
// Assert channel on application loading
rmq.rpc('my-function');
rmq.rpc('my-function').call({
someField: "Hello world!"
}).then(result => {
console.log("RETURNED VALUE:", result);
});