File system backed lock-free and atomic message queue for Node.js. Stores messages using Maildir format to avoid using file locks.
- Node.js >= 6.0
$ npm install @munogu/maildir-queue
// module dependencies
const Queue = require('@munogu/maildir-queue')
// initialize queue
let queue = new Queue('your_queue_name')
// 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)
})
queue.add({
this: 'is',
the: 'payload object'
})
queue.pop(item => {
console.log('received item with id %s', item.id)
})
Returns total count of items in the queue.
queue.count().then(count => {
console.log('%s item(s) found', count)
})
Deletes all expired items according to ttl
setting.
queue.empty().then(() => {
console.log('queue emptied successfully!')
})
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.