egg-grpc-client
Install
$ npm i egg-grpc-client --save
Usage
// {app_root}/config/plugin.jsexportsgrpcClient = enable: true package: 'egg-grpc-client';
Configuration
// {app_root}/config/config.default.js exportsgrpcClient = loaderOption: keepCase: true longs: String enums: String defaults: true oneofs: true client: protoPath: 'app/grpc' host: '0.0.0.0' port: '50051' ////app.grpcClient // clients: { // server1: { // protoPath: 'app/grpc', // host: '0.0.0.0', // port: '50051' // }, //app.grpcClient.get('server1') // server2:{ // protoPath: 'app/grpc', // host: '0.0.0.0', // port: '50051' // } //app.grpcClient.get('server2') // };
see config/config.default.js for more detail.
Example
// {app_root}/config/config.default.js
exports.grpcClient = {
loaderOption: {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
},
clients: {
passport:{
protoPath: 'app/grpcClient/passport',
host: '0.0.0.0',
port: '50051'
}
}
};
//{app_base}/app/grpcClient/passport/ProfileService.proto
syntax = "proto3";
package passport.profile;
service ProfileService {
rpc getUserInfo (UserID) returns (UserInfo) {
}
}
service ProfileService2 {
rpc getUserInfo (UserID) returns (UserInfo) {
}
}
message UserID {
string userId = 1;
}
message UserInfo {
string userId = 1;
string username = 2;
string avatar = 3;
string nickname = 4;
string gender = 5;
}
//use
app.grpcClient.get('passport').passport.profile.ProfileService.getUserInfo({userId: '230371e2-eb07-4b2b-aa61-73fd27c5387e'}).then((res) => {
console.log(res)
}).catch((e) => {
console.log(e)
})
//app.[passport.profile].* == `package passport.profile` in *.proto ;
Server
Please open an issue egg-grpc-server.
Questions & Suggestions
Please open an issue here.