A simple queue for jobs made using rabbitmq.
Install and start rabbitmq. Here's the link to download and installation guide.
npm i rabbitmqueue
Create a js file on the root directory of your project. Let's call it rmq.js
.
const rabbitmqueue = require('devnagri-rabbitmq-node');
const consumers = {
'default': function (data) {
console.dir(data);
}
};
rabbitmqueue.init("amqp://localhost", consumers);
Here consumers
is an object containing queue names as key and job handling function as value.
We initialize the daemon using init
where you must pass rabbitmq connection string and consumer object.
node rmq.js
We can use PM2 on production.
Here's how to push messages to queue.
const rabbitmqueue = require('devnagri-rabbitmq-node');
const producer = rabbitmqueue.producer("amqp://localhost", ['default']);
producer.produce('default', {
'key1': 'value1',
'key2': 'value2'
});