egg-ebus

0.1.4 • Public • Published

egg-ebus

NPM version build status [Test coverage][codecov-url] [![David deps][david-image]][david-url] [Known Vulnerabilities][snyk-url] npm download

Install

$ npm i egg-ebus --save

Usage

// {app_root}/config/plugin.js
exports.ebus = {
  enable: true,
  package: 'egg-ebus',
};

Configuration

// {app_root}/config/config.default.js
exports.ebus = {
};
例如
exports.ebus = {
    app: true,
    agent: true,
    debug: true,
    concurrency: 2,
    listener: {
      baseDir: 'events',//配置监听事件的目录
      options: {
        attempts: 5,
        backoff: {
          delay: 1000,
          type: 'fixed',
        },
      },
    },
    limiter: {
      max: 10,
      duration: 1000
    },
    redis: {
      host: 'localhost',
      port: 6379,
      password: "",
      db: 0,
    },
    queue: {
      default: 'default_bus', // 默认队列名称
      prefix: 'ebus', // 队列前缀
    },
    queues: {
      worker: {
        concurrency: 2,
      },
    },
  }

see config/config.default.js for more detail.

关于监听文件

在配置监听事件的目录下,创建监听文件,可看考源码的demo/app/events/的orderListener文件

Example

get 获取队列 emit 添加队列
例如 const point = await this.app.ebus.emit("order_action", { ord_no: 123 }, { delay: 1000, removeOnComplete: true, removeOnFail: true });此用例用于发送延时队列

cleanOn (Removes jobs in a specific state, but keeps jobs within a certain grace period) delAll (Completely obliterates a queue and all of its contents.) drain (Removes all jobs that are waiting or delayed, but not active, waiting-children, completed or failed.)

在controller里 使用this.app.ebus.emit(监听的事件,传输数据,可配置delay毫秒数) 可以参考bullmq https://docs.bullmq.io/guide/introduction https://bullmq.io

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-ebus

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

14.6 kB

Total Files

12

Last publish

Collaborators

  • yecao007