Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-ons

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-ons

aliyun ons plugin for egg

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
2
Weekly downloads
 
Created
Source

egg-ons

NPM version build status Test coverage David deps Known Vulnerabilities npm download

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!

License

MIT

Keywords

FAQs

Package last updated on 26 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc