Skip to content

yuu2lee4/egg-bullmq

 
 

Repository files navigation

README

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

中文版

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

Install

$ npm i egg-bullmq --save

Usage

// {app_root}/config/plugin.js
exports.bullmq = {  // plugin name is 'bull'
  enable: true,
  package: 'egg-bullmq', // package name is 'egg-bullmq'
};

Configuration

Single queue

// {app_root}/config/config.default.js
exports.bullmq = {
  client: {
    name: 'queue-name',
    redis: {
      host: 'localhost',
      port: 6379,
      db: 0,
    },
  },
};

Multiple queue (recommended)

exports.bullmq = {
  clients: {
    q1: { name: 'q1' },
    q2: { name: 'q2' },
  },
  default: {
    redis: {
      host: 'localhost',
      port: 6379,
      db: 0,
    },
  },
};

Example

// 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.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%