Can grpc nodejs Client be shared?

356 views
Skip to first unread message

lsk

unread,
Nov 2, 2016, 9:06:48 AM11/2/16
to grpc.io
Hi I tried to find info about it but failed. I'm using grpc nodejs client in Express.js server app and I can not figure out if I can share a client object instance between multiple http request.

I already figure out that I need to use promises to properly achieve Async calls. But that is another story. Each http request is managed by Express middelware stack, which define a set of functions which will be called before returning the response (in simplication).  At some point I call let say client.sayHello(). Can I do that? Or do I need to have a pool of client object?

Also how to check the status of client connection? If it is busy, ready, etc.?

Lsk.

Michael Lumish

unread,
Nov 2, 2016, 1:30:18 PM11/2/16
to lsk, grpc.io
Yes, you can use a single client to make multiple simultaneous calls. In fact, this connection sharing is one of the major benefits of using gRPC.

You can't exactly check the current status, but you can use grpc.waitForClientReady, which calls your callback when either the client has finished attempting to connect or the deadline has passed, and passes an error if the client has not connected successfully. But using that function is generally unnecessary. If you make a call on a client that is not currently connected, it will do the right thing and start trying to connect.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/de61e8d7-9e48-4302-ac23-73b0da4021d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted
Message has been deleted

lsk

unread,
Nov 3, 2016, 5:31:04 AM11/3/16
to grpc.io, leszek....@gmail.com
Thanks a lot. Now it is all clear.
Reply all
Reply to author
Forward
0 new messages