egg-rocketmq-http

1.3.7 • Public • Published

egg-rocketmq-http

provides egg bindings for the ali rocketMQ.

npm download NPM version GitHub issues GitHub

Install

$ npm i egg-rocketmq-http --save

Usage

// {app_root}/config/plugin.ts
export const rocketMQ = {
  enable: true,
  package: 'egg-rocketmq-http',
}

// {app_root}/config/config.default.ts
export const rocketMQ = {
    ...
    consumers: [
      {
        consumer: 'cons',
        tags: string[ 'tagA' ]
      },
    ] ,
};

// Producer
this.app.mq.publish(body, 'tagA');

// Consumer
// {app_root}/app/mq/cons.ts
import { Consumer, Message } from 'egg-rocketmq-http';
export default class Cons extends Consumer {
  private name = 'cons';
  async tagA(message: Message) {
    console.log('cons\'s tagA action: %s', message.MessageBody);
    this.app.mq.ack(this.name, [ message.ReceiptHandle ]);
  }
}

see lib/discovery/controller.ts for more detail.

Configuration

// {app_root}/config/config.default.ts
exports.rocketMQ = {
    log: true, // it will log in the path /logs/mq.log
    endpoint: '',
    accessKeyId: '',
    accessKeySecret: '',
    securityToken: null,
    instanceId: '',
    topic: '',
    consumers: {
      xxxxx: {
        tags: string[ 'test' ], // tags the app watched
        numOfMessages?: 3,
        waitSeconds?: 30,
        send?: 'random', // default, send to a random app, or you can set to 'all'
        sure?: false, // must be success, it will send ack automatically
        consumeWait?: 30000 // maximum waiting time for consumption, default: 30000(ms)
      },
    } ,
};

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

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-rocketmq-http

Weekly Downloads

4

Version

1.3.7

License

MIT

Unpacked Size

47.5 kB

Total Files

18

Last publish

Collaborators

  • uccu