0.0.5 • Published 6 years ago

simple-work-queues v0.0.5

Weekly downloads
9
License
ISC
Repository
github
Last release
6 years ago

simple-work-queues

Delay your functions to queues backed by RabbitMQ

Install

$ npm install simple-work-queues

Usage

For example,

worker.js

const { Worker } = require('simple-work-queues');
const { fn1, fn2 } = require('./tasks'); // import functions from whereever you want

const config = {
  brokerURL: 'your-rabbitmq-broker-url',
  noAck: false, //boolean
  prefetch: 1, //concurrency for every worker, default 1, only useful when noAck is false
  routes: {
    queue1: fn1,
    queue2: fn2,
  }
}

const worker = Worker(config);

worker.listen('queue1');
worker.listen('queue2', (err, data) => {console.log(data)}); //add callback function(optional), data is what returned by your function

dispatcher.js

const { Producer } = require('simple-work-queues');
const { fn1, fn2 } = require('./tasks'); // import functions from whereever you want

const producer = Producer(config); // config is the same with the one in worker.js

producer.delay(fn1)(); //wrap your function and call it whenever u want
producer.delay(fn2)();

Author

HoMuchen

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago