Nilotpal
Nilotpal

Reputation: 3588

How to make sure that gRPC client is connected to a remote/local gRPC Service even before the first rpc call to service

Is there a debugging method or way to know whether my gRPC client is connnectable to gRPC remote/local service. I want to know this even before the first call to grpc service call.

Thanks!!

Upvotes: 3

Views: 1973

Answers (1)

voidzcy
voidzcy

Reputation: 610

The network connection won't be established until you made the first RPC call (aka, lazy connect). To overcome transient network failures and ensure your RPC calls are sent out after connecting successfully, you can use waitForReady(). There is also a doc for it here.

There is another option on the ManagedChannel that you can force it to connect: ManagedChannel.getState(true). You can attach a callback via ManagedChannel.notifyWhenStateChanged(...) to monitor if the connection succeeded.

Upvotes: 2

Related Questions