egg-rocketmq-http
v1.3.8
Published
provides egg bindings for the rocketmq.
Downloads
30
Maintainers
Readme
egg-rocketmq-http
provides egg bindings for the ali rocketMQ.
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.