项目作者: shawjia

项目描述 :
Thrift plugin for egg
高级语言: JavaScript
项目地址: git://github.com/shawjia/egg-thrifty.git
创建时间: 2018-03-31T07:41:46Z
项目社区:https://github.com/shawjia/egg-thrifty

开源协议:MIT License

下载


egg-thrifty

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

Install

  1. $ npm i egg-thrifty --save

Usage

  1. // {app_root}/config/plugin.js
  2. exports.thrift = {
  3. enable: true,
  4. package: 'egg-thrifty',
  5. };

Configuration

  1. // {app_root}/config/config.default.js
  2. const thrift = require('thrift');
  3. exports.thrift = {
  4. app: true,
  5. agent: false,
  6. default: {
  7. timeout: 4000,
  8. connect_timeout: 4000,
  9. max_attempts: 10,
  10. reconnect: false,
  11. transport: thrift.TFramedTransport,
  12. protocol: thrift.TBinaryProtocol,
  13. },
  14. };

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

Example

  1. // config.js
  2. config.thrift = {
  3. clients: {
  4. test: {
  5. host: 'localhost',
  6. port: 1111,
  7. genjs: path.join(appInfo.baseDir, 'path/to/ThriftService.js'),
  8. reconnect: true,
  9. },
  10. },
  11. };
  12. // service/test.js
  13. 'use strict';
  14. const { Service } = require('egg');
  15. class TestService extends Service {
  16. doSth() {
  17. const { client } = this.app.thrift.get('test');
  18. client.doSth(null, (err, data) => {
  19. });
  20. }
  21. }
  22. module.exports = SubscribeService;

License

MIT