ali haider
ali haider

Reputation: 20242

getting connection state for GRPC

I am trying to get the connection state for a GRPC (Java API) connection via the call copied below. Based on the notes I could find online, it seemed as if GRPC client would lazily connect to the server on the first service call & if I wanted to establish the connection before the service call, I could use this option. However, this call seems to always prevent my application from connecting to the server and I was wondering if I had to rely on a different call/mechanism.

GRPC version: 1.1.2
JDK version:1.8

final ManagedChannelBuilder<?> channelBuilder = connection.getSecure();  //this forms a secure connection
channel = channelBuilder.build();
ConnectivityState connectivityState = channel.getState(true); //referenced in question above
asyncStub = MonetaGoConnectGrpc.newStub(channel);

Upvotes: 3

Views: 8478

Answers (1)

Eric Anderson
Eric Anderson

Reputation: 26464

Update: getState(true) was implemented in grpc-java v1.6.1 (Aug 31, 2017), although it was incomplete. It was later completed in grpc-java v1.11.0 (Mar 30, 2018).

Original answer:

It isn't currently implemented for most ManagedChannels. The API was introduced for the new LoadBalancer API, but now not even LoadBalancer is using it.

I've filed an issue to improve the documentation until it is implemented.

Your understanding of the Channel's behavior is correct. It lazily connects and this is the API that can force-connect the Channel. Unfortunately, it isn't yet implemented and there's not an alternative other than issuing an RPC.

Upvotes: 2

Related Questions