https://github.com/homuchen/simple-work-queues
https://github.com/homuchen/simple-work-queues
delay-queue delayed-jobs delayed-tasks message-queue rabbitmq-client
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/homuchen/simple-work-queues
- Owner: HoMuChen
- Created: 2018-03-18T09:34:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-05T14:44:07.000Z (over 7 years ago)
- Last Synced: 2025-07-01T12:02:38.966Z (3 months ago)
- Topics: delay-queue, delayed-jobs, delayed-tasks, message-queue, rabbitmq-client
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-work-queues
Delay your functions to queues backed by RabbitMQ
## Install
$ npm install simple-work-queues
## Usage
For example,
worker.js
```javascript
const { Worker } = require('simple-work-queues');
const { fn1, fn2 } = require('./tasks'); // import functions from whereever you wantconst 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
```javascript
const { Producer } = require('simple-work-queues');
const { fn1, fn2 } = require('./tasks'); // import functions from whereever you wantconst 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