egg-thrifty
v0.2.1
Published
Thrift plugin for egg
Downloads
4
Readme
egg-thrifty
Install
$ npm i egg-thrifty --save
Usage
// {app_root}/config/plugin.js
exports.thrift = {
enable: true,
package: 'egg-thrifty',
};
Configuration
// {app_root}/config/config.default.js
const thrift = require('thrift');
exports.thrift = {
app: true,
agent: false,
default: {
timeout: 4000,
connect_timeout: 4000,
max_attempts: 10,
reconnect: false,
transport: thrift.TFramedTransport,
protocol: thrift.TBinaryProtocol,
},
};
see config/config.default.js for more detail.
Example
// config.js
config.thrift = {
clients: {
test: {
host: 'localhost',
port: 1111,
genjs: path.join(appInfo.baseDir, 'path/to/ThriftService.js'),
reconnect: true,
},
},
};
// service/test.js
'use strict';
const { Service } = require('egg');
class TestService extends Service {
doSth() {
const { client } = this.app.thrift.get('test');
client.doSth(null, (err, data) => {
});
}
}
module.exports = SubscribeService;