1.7.0 • Published 6 years ago
egg-grpc-server v1.7.0
egg-grpc-server
Install
$ npm i grpc -g
$ npm i egg-grpc-server --save
Usage
// {app_root}/config/plugin.js
exports.grpcServer = {
enable: true,
package: 'egg-grpc-server',
};
Configuration
// {app_root}/config/config.default.js
exports.grpcServer = {
protoPath: 'app/grpc', //*.proto path
extendPath: 'app/grpc', //service path
host: '0.0.0.0',
port: '50051',
loaderOption: {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
}
};
see config/config.default.js for more detail.
Example
// {app_root}/app/grpc/ProfileService.proto
syntax = "proto3";
package passport.auth;
service AuthService {
rpc roles (UserReq) returns (UserRes) {
}
}
message UserReq {
string userId = 1;
string clientId = 2;
}
message UserRes{
string userId = 1;
string clientId = 2;
}
// {app_root}/app/grpc/passport/profile/ProfileService.js
const BaseGrpc = require('egg-grpc-server').BaseGrpc;
class ProfileService extends BaseGrpc {
async getUserInfo() {
this.app.coreLogger.info("echo");
const params = this.call.request;
const user = await this.app.model.User.findOne({where: {userId: params.userId}});
if (!user) throw new Error('user_none');
return {
userId: user.userId,
username: user.username,
nickname: user.nickname,
avatar: user.avatar,
gender: user.gender
}
}
}
module.exports = ProfileService;
// {app_root}/app/grpc/[passport/profile/]ProfileService.js == `package passport.profile` in *.proto ;
see demo for more detail.
client
Please open an issue egg-grpc-client.
Questions & Suggestions
Please open an issue here.
License
1.7.0
6 years ago
1.6.8
6 years ago
1.6.6
6 years ago
1.6.5
6 years ago
1.6.4
6 years ago
1.6.3
6 years ago
1.6.2
6 years ago
1.6.1
6 years ago
1.6.0
6 years ago
1.5.9
6 years ago
1.5.8
6 years ago
1.5.7
6 years ago
1.5.6
6 years ago
1.5.5
6 years ago
1.5.4
6 years ago
1.5.3
6 years ago
1.5.2
6 years ago
1.5.1
6 years ago
1.5.0
6 years ago
1.1.0
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago