@munogu/maildir-queue
v0.1.2
Published
File system backed lock-free and atomic message queue for Node.js
Downloads
5
Readme
Maildir queue
File system backed lock-free and atomic message queue for Node.js. Stores messages using Maildir format to avoid using file locks.
Requirements
- Node.js >= 6.0
Installation
$ npm install @munogu/maildir-queue
Quick Start
// module dependencies
const Queue = require('@munogu/maildir-queue')
// initialize queue
let queue = new Queue('your_queue_name')
Usage
// module dependencies
const Queue = require('@munogu/maildir-queue')
// queue options
let options = {
// output directory
dir: '/path/to/output/directory',
// time to live in milliseconds
ttl: 86400 * 1000,
// max retries, -1 for infinite, 0 for no retries
retries: 10
}
// initialize queue
let queue = new Queue('your_queue_name', options)
// add new item to queue
queue.add({
foo: 'bar'
})
// pop item from queue
queue.pop(item => {
console.log('item id %s', item.id)
})
API
add(payload = object) - Promise
queue.add({
this: 'is',
the: 'payload object'
})
pop(handler = function) - Promise
queue.pop(item => {
console.log('received item with id %s', item.id)
})
count() - Promise
Returns total count of items in the queue.
queue.count().then(count => {
console.log('%s item(s) found', count)
})
Debugging
Maildir queue along with many of the libraries it's built with support the DEBUG environment variable from debug which provides simple conditional logging.
For example to see all maildir-queue specific debugging information just pass DEBUG=queue*
and upon boot you'll see the list of middleware used, among other things.