grpc-experimental-server
gRPC experimental server that supports koa-like interceptors
Usage
npm i ges grpc
import ExperimentalServer from 'ges';
const server = new ExperimentalServer();
server.addService();
server.use(async (context, next) => {
const start = Date.now();
try {
await next();
} finally {
const costtime = Date.now() - start;
console.log('costtime is', costtime);
console.log('unary response is ', context.response);
}
});
serer.bind();
server.start();
gRPC
has 4 kinds of call:
handle type | request is stream or not | response is stream or not |
---|
handleUnaryCall | ❌ | ❌ |
handleClientStreamingCall | ✅ | ❌ |
handleServerStreamingCall | ❌ | ✅ |
handleBidiStreamingCall | ✅ | ✅ |
Context
call
current gRPC calldefinition
the method definition of current callresponse
response if response is not stream
onFinished(...)
you can listen on call finish event, no matter response of current call is stream or not. So you don't need to care about what kind is the call. It is very useful to do something like tracing
, logging
Notes
await next()
would wait the call to be finished if response is not stream.