egg-delayed-queue
v1.0.2
Published
A priority job queue backed by redis, built for eggjs.
Downloads
3
Maintainers
Readme
egg-delayed-queue
A priority queue queue backed by redis, built for eggjs.
Install
$ yarn add egg-delayed-queue
Usage
// {app_root}/config/plugin.js
exports.queue = {
enable: true,
package: 'egg-delayed-queue',
};
Configuration
// {app_root}/config/config.default.js
'use strict';
exports.queue = {
client: {
queuePrefix: 'q',
redis: {
port: 6379,
host: '127.0.0.1',
auth: '',
db: 3,
// see https://github.com/mranney/node_redis#rediscreateclient
options: {
},
},
},
// clients: {}
};
see config/config.default.js for more detail.
Example
// 在 app.js 里面调用 如果需要用到ctx 可以 const ctx = app.createAnonymousContext();
app.queue.process('orderNo', (job, done) => {
// 这里可以调用service里面的方法来消费这些信息
const ctx = app.createAnonymousContext();
ctx.service.home.dealOrder(job.data, done); // dealOrder是自定义的方法
});
// 在需要的地方订阅一个消息
app.queue.create('orderNo', {
orderNo: '1111111',
create_time: Date.now()
}).delay(milliseconds) // 延时多少毫秒
.save();
form more config please see here
Questions & Suggestions
Please open an issue here.