trooba-grpc-transport
gRPC transport for trooba pipeline
Install
npm install trooba-grpc-transport --save
Usage
Service invocation
var grpcTransportFactory = require('trooba-grpc-transport');
require('trooba')
.transport(grpcTransportFactory, {
protocol: 'http:',
hostname: 'grpc.service.my',
port: 50001,
proto: require.resolve('path/to/hello.proto'),
connectTimeout: 100,
socketTimeout: 1000
})
.create()
.hello('Bob', function (err, response) {
console.log(err, response)
});
Sample proto definition:
syntax = "proto3";
option java_package = "com.app.sample.grpc";
service Hello {
rpc SayHello ( HelloRequest) returns ( HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
Sample server
var Grpc = require('grpc');
var hello_proto = Grpc.load(require.resolve('./path/to/hello.proto'));
function sayHello(call, callback) {
callback(null, {message: 'Hello ' + call.request.name});
}
module.exports.start = function start(port) {
var server = new Grpc.Server();
console.log('listening on port:', port);
server.bind('localhost:' + port, Grpc.ServerCredentials.createInsecure());
server.addProtoService(hello_proto.Hello.service, {sayHello: sayHello});
server.start();
return server;
};
module.exports.proto = hello_proto;