egg-bullmq

0.0.7 • Public • Published

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

/egg-bullmq/

    Package Sidebar

    Install

    npm i egg-bullmq

    Weekly Downloads

    19

    Version

    0.0.7

    License

    MIT

    Unpacked Size

    11.2 kB

    Total Files

    9

    Last publish

    Collaborators

    • skyblue