0.0.9 • Published 4 years ago

egg-tchannel v0.0.9

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

egg-tchannel

tchannel plugin for egg.

Install

$ npm i tchannel  
$ npm i egg-tchannel  

Configuration

egg-tchannel with default configurations below:

  • tchannelModule: 'tchannel',
  • cacheThriftTime: 0 thriftIDL cache millisecond, 0 => permanent
  • thriftIDLPath: path.join(appInfo.baseDir, "thrift_idl")
  • timeout: 2500
  • thriftOptions:

    strict: false
    allowOptionalArguments: true

// {app_root}/config/config.default.js
exports.tchannel = {
  // timeout: 2500,
};

Usage

// {app_root}/app.js

class AppBootHook {
  constructor (app) {
    this.app = app;
  }

  async didLoad () {
    // registry should return a promise, like:
    function registry(serviceName, tag) {
      return Promise.resolve([
        {
          peer: '192.x.x.10:6666'
        },
        {
          peer: '192.x.x.11:6666'
        }
      ]);
    }
    this.app.tchannel.configure({
      registry: registry
    });
  }
}

module.exports = AppBootHook;

In controller, you can use app.tchannel.request.

// app/controller/home.js

module.exports = app => {
  return class HomeController extends app.Controller {
    async index() {
      const { ctx, app } = this;
      const res = await app.tchannel.request({
        serviceName: 'serviceName',
        method: 'method',
        headers: {},
        body: {
         'some key': 'some data',
        },
        tag: 'group1',
        options: {}
      });
      ctx.body = res;
    }
  };
};

Questions & Suggestions

Please open an issue here.

License

MIT

0.0.9

4 years ago

0.0.8-beta.1

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago