@tuia/egg-rocketmq

1.0.0 • Public • Published

egg-rocketmq

Install

$ npm i egg-rocketmq --save

Configuration

// {app_root}/config/plugin.js
exports.rocketmq = {
  enable: true,
  package: 'egg-rocketmq'
};
// {app_root}/config/config.default.js
exports.rocketmq = {
  producer: {
    options: {
      nameServer: 'your rocketmq server',
      compressLevel: 5,
      sendMessageTimeout: 3000,
      maxMessageSize: 1024 * 128
    },
    topicsList: [{
      groupId: 'test-1',
      instanceName: '', // optional
      groupName: 'test-1',
      topic: 'test-1'
    }, {
      groupId: 'test-2',
      instanceName: '', // optional
      groupName: 'test-2',
      topic: 'test-2'
    }],
  },
  consumer: {
    options: {
      nameServer: 'your rocketmq server',
    },
    topicsList: [{
      topic: 'test-1',
      groupId: 'test-1',
      groupName: 'test-1',
      instanceName: '', // optional
      serviceFloderName: 'consumer', // service floder name
      fileNameWithMethod: 'receive.testMsg1' // service filename and method name
    }, {
      topic: 'test-2',
      groupId: 'test-2',
      groupName: 'test-2',
      instanceName: '', // optional
      serviceFloderName: 'consumer',
      fileNameWithMethod: 'receive.testMsg2'
    }]
  }
};

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

Usage

// producer
await this.ctx.service.producer.index('test-1', {
  body: 'I am your dad-1'
});

// consumer
const Service = require('egg').Service;
module.exports = class Receive extends Service {
  async testMsg1(topic, payload) {
    this.ctx.logger.info(topic, payload);
  }
};

see example/app/service/producer.js and example/app/service/consumer/receive.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i @tuia/egg-rocketmq

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.11 kB

Total Files

5

Last publish

Collaborators

  • any-u
  • dinglh
  • candy_dd
  • wintersun97
  • tump
  • inuanfeng
  • zhoucheng
  • zhangmin173
  • aiduck
  • chao.zhou
  • babalk
  • leitingting
  • nbseven
  • linhao-vue
  • liusandy