grpc-spring icon indicating copy to clipboard operation
grpc-spring copied to clipboard

Client Connection Status

Open alex-damico opened this issue 4 years ago • 7 comments

Hello everyone I would like to get the connection status of the grpc client, is it possible?

Example:

  • grpc client is online
  • grpc server starts after 5 minutes

When my grpc client reconnects, it must send a message to the server.

Thank you for your support

alex-damico avatar Jan 19 '21 18:01 alex-damico

This might help you: ManagedChannel#notifyWhenStateChanged(...)

ST-DDT avatar Jan 19 '21 19:01 ST-DDT

@ST-DDT Can you show me an example of grpc-spring-boot-starter?

alex-damico avatar Jan 19 '21 19:01 alex-damico

Unfortunately, there is currently no way in this library to get the ManagedChannel instance without using a little bit of a workaround. You have to extend AbstractChannelFactory (or the existing implementations) and extend the newManagedChannel or watchConnectivityState method to your needs (or use reflection to access the channels field). This will probably change in a future version, but there isn't a timeline for that yet.

When my grpc client reconnects, it must send a message to the server.

What is the purpose of that message? Is it used for authentication? Then you might be better of with using CallCredentials. I'm not sure, whether grpc supports connection level authentication.

Please note, that the client doesn't just reconnect by itself, AFAICT it has to be triggered by a new call. It might be better to just setup a scheduled task, that sends the request.

ST-DDT avatar Jan 19 '21 23:01 ST-DDT

Is it enough to setup intermediateconnecttimeout to non-zero for channel and set grpc.cleint..enableKeepAlive propery to true to guarantee that channel is always warmed up ? actually i also suffer from not getting managed channel with ease like someService.getChannel().getState(true) to ensure channel is up before call.

slogic avatar Feb 18 '21 13:02 slogic

Is it enough to setup intermediateconnecttimeout to non-zero for channel and set grpc.cleint..enableKeepAlive propery to true to guarantee that channel is always warmed up ?

I'm not sure, maybe you should ask this question over at grpc-java.

actually i also suffer from not getting managed channel with ease like someService.getChannel().getState(true) to ensure channel is up before call.

I plan to adjust the channel factory to allow the users to access the underlying managed channels. Why do you need to ensure the channel is up before the call?

ST-DDT avatar Feb 18 '21 17:02 ST-DDT

I need it for deterministic deadline.

slogic avatar Feb 18 '21 20:02 slogic

Unfortunately, there is currently no way in this library to get the ManagedChannel instance without using a little bit of a workaround. You have to extend AbstractChannelFactory (or the existing implementations) and extend the newManagedChannel or watchConnectivityState method to your needs (or use reflection to access the channels field). This will probably change in a future version, but there isn't a timeline for that yet.

When my grpc client reconnects, it must send a message to the server.

What is the purpose of that message? Is it used for authentication? Then you might be better of with using CallCredentials. I'm not sure, whether grpc supports connection level authentication.

Please note, that the client doesn't just reconnect by itself, AFAICT it has to be triggered by a new call. It might be better to just setup a scheduled task, that sends the request.

Anyone tried this ? some sample code ?

313hemant313 avatar Aug 09 '23 16:08 313hemant313