Plugin to handle jobs and messages with Bull in Egg.js.
Bull is a fast, reliable, Redis-based queue for Node.
$ npm i egg-bull-queue --save
If you use TypeScript:
$ npm i @types/bull --save-dev
// {app_root}/config/plugin.js
exports.bull = { // plugin name is 'bull'
enable: true,
package: 'egg-bull-queue', // package name is 'egg-bull-queue'
};
// {app_root}/config/config.default.js
exports.bull = {
client: {
name: 'queue',
redis: {
host: 'localhost',
port: 6379,
db: 0,
},
},
};
exports.bull = {
clients: {
q1: { name: 'q1' },
q2: { name: 'q2' },
},
default: {
redis: {
host: 'localhost',
port: 6379,
db: 0,
},
},
};
app.bull.process(job => {
console.log(job.data, job1); // 'this is a job'
});
app.bull.add({ job1: 'this is a job' });
For Bull's api read Reference for more details.