0.0.3-beta • Published 4 years ago

egg-pubsub v0.0.3-beta

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

egg-pubsub

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

Install

$ npm i egg-pubsub --save

Usage

// {app_root}/config/plugin.js
exports.pubsub = {
  enable: true,
  package: 'egg-pubsub',
};

Configuration

// {app_root}/config/config.default.js
exports.pubsub = {
  client: {
    name: 'pubsubName',
    /**
     * @var topic google cloud topic name, it is optional.
     */
    topic: 'topic name',
    /**
     * @var subscription google cloud subscription name, it is optional.
     */
    subscription: 'subscribe name',

    /**
     * the document contains more detailed information about the settings of pubsub
     * https://cloud.google.com/nodejs/docs/reference/pubsub/0.28.x/PubSub
     */
  }
};
// {app_root}/pubsub/pubsubName.js
module.exports = pubsubApp => {
  pubsubApp.router.register('test', async context => {
    console.log(context.cmd);
  });
}
// {app_root}/app/controller/home.js
const controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    await this.app.pubsub.publish('test');
  }
}

module.exports = HomeController;

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

Example

Questions & Suggestions

Please open an issue here.

License

MIT