egg-wd-ons
v3.7.0
Published
aliyun ons plugin for egg
Downloads
54
Readme
egg-ons
aliyun ons plugin for egg
Install
$ npm i egg-ons --save
Usage
// {app_root}/config/plugin.js
exports.ons = {
enable: true,
package: 'egg-ons',
};
Configuration
// {app_root}/config/config.default.js
exports.ons = {
default: {
accessKey: 'your-accessKey',
secretKey: 'your-secretKey',
// prod:http://onsaddr-internal.aliyun.com:8080/rocketmq/nsaddr4client-internal
// dev: http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet
// onsAddr: 'http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet',
},
sub: [{
consumerGroup: 'your-consumer-group',
topics: [
'your-topic',
],
}],
pub: [{
producerGroup: 'your-producer-group',
topics: [
'your-topic',
],
}],
};
see config/config.default.js for more detail.
Example
Consumer
put your subscription codes under the folder {app_root}/app/ons
and named as the topic name e.g TP_NAME.js
.
├── app
│ ├── ons
│ │ └── TP_NAME.js
│ ├── public
│ └── router.js
├── config
│ └── config.default.js
├── package.json
you should implment a subscriber as blow
// TP_NAME.js
'use strict';
class TestSubscriber {
constructor(ctx) {
this.ctx = ctx;
}
* subscribe(msg) {
yield this.ctx.service.messageService.process(msg);
}
static get subExpression() {
return 'TagA';
}
}
module.exports = TestSubscriber;
see RPC for more detail.
Producer
using app.ons / ctx.ons
to create & send messages
const Message = ctx.ons.Message;
const msg = new Message('TP_NAME', // topic
'TagA', // tag
'Hello ONS !!!' // body
);
const sendResult = yield ctx.ons.send(msg);
Questions & Suggestions
Please open an issue here.
Secure Keys
ping @fengmk2 to give you the access key!