Skip to content
Akash Babu edited this page Jul 9, 2018 · 4 revisions

grpc-pool

In simple words, it's just an Efficient light-weight library implementing gRPC connection pool in Nodejs!!

Introduction

Do you feel like the gRPC Connections are not scaling up ?
Or when you try to make recursive connections, do you face this error Error 8: RESOURCE EXHAUSTED ?
Does it feel annoying to use callback only for gRPC while the rest of the application is in Async/Await ?
Do you want to logically segregate your Namespace for RPC Methods ?
Then You are in the right place

If you don't want to share .proto files with the clients (as this is subjected to changes on the server), but would only like to expose the gRPC methods, then this library would be a right fit for your needs.
A gist of the same would look like below:

# hello.proto
syntax = "proto3";

package Hello;

service Greeting {
    rpc _Hi(Request) returns (Reply) {};
    rpc _ReadStream(Request) returns (stream Reply) {};
    rpc _WriteStream(stream Request) returns (Reply) {};
    rpc _BothStream(stream Request) returns (stream Reply) {};
}

message Request {
    string msg = 1;
}

message Reply {
    string resp = 1;
}

After declaring the .proto file as shown above, you can expose your gRPC methods as below:

const client = new GRPCClient(path.join(__dirname, 'hello.proto'), {
    maxConnections : 5,
    packageName    : 'Hello',
    serviceName    : 'Greeting',
    url            : 'localhost:50001',
    prefix         : 'RPC'
});

export const { RPC_Hi, RPC_ReadStream, RPC_WriteStream, RPC_BothStream } = client;

Now the above code would result in exporting the methods RPC_Hi, RPC_ReadStream, RPC_WriteStream & RPC_BothStream just like you would expose in the normal libraries, but the advantage that one might find in here is that each methods is wrapped with connection pool hidden under the hood.
Also note that the client need not have to worry about importing or loading the gRPC file at their end, instead they can directly call the exported methods just like invoking locally declared methods ( Actual RPC type 😜)

Clone this wiki locally