Plugin to handle jobs and messages with BullMQ in Egg.js and follow Egg's way.
BullMQ is a fast, reliable, Redis-based queue for Node.
Base on egg-bull-queue
$ npm i egg-bullmq --save
// {app_root}/config/plugin.js
exports.bullmq = { // plugin name is 'bull'
enable: true,
package: 'egg-bullmq', // package name is 'egg-bullmq'
};
// {app_root}/config/config.default.js
exports.bullmq = {
client: {
name: 'queue-name',
redis: {
host: 'localhost',
port: 6379,
db: 0,
},
},
};
exports.bullmq = {
clients: {
q1: { name: 'q1' },
q2: { name: 'q2' },
},
default: {
redis: {
host: 'localhost',
port: 6379,
db: 0,
},
},
};
// add job to queue
const queue = app.bullmq.get('queueName')
await queue.add('namespace', { text: 'this is a job' }, { delay: 5000, lifo: true })
const count = await queue.count()
//worker
const worker = new Worker(queueName, async job => {
// do the job
console.log(process.pid, job.data)
job.updateProgress(42)
// await ctx.service.someTask.run()
}, { connection })
// and look at ./example
For BullMQ's api read Reference for more details.