0.0.9 • Published 1 year ago

@yuu2lee4/egg-bullmq v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

NPM version build status Test coverage David deps Known Vulnerabilities npm download

English

BullMQ 是一个快速的,可靠的,基于 Redis 的 Node.js 队列服务。

安装

$ npm i egg-bullmq --save

使用

// {app_root}/config/plugin.js
exports.bullmq = {  // 插件名称是 'bullmq'
  enable: true,
  package: 'egg-bullmq'
};

配置

单一队列

// {app_root}/config/config.default.js
exports.bullmq = {
  client: {
    name: 'queue',
    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 })

// 具体查看 ./example

关于 BullMQ 的 API 和使用请阅读 Reference

License

MIT

0.0.9

1 year ago

0.0.8

2 years ago