egg-grpc-server
Install
$ npm i grpc -g$ npm i egg-grpc-server --save
Usage
// {app_root}/config/plugin.jsexportsgrpcServer = enable: true package: 'egg-grpc-server';
Configuration
// {app_root}/config/config.default.js exportsgrpcServer = 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 passportauth; service AuthService rpc { } 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 = BaseGrpc; async { thisappcoreLogger; const params = thiscallrequest; const user = await thisappmodelUser; if !user throw 'user_none'; return userId: useruserId username: userusername nickname: usernickname avatar: useravatar gender: usergender } moduleexports = 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.