grpc-ecosystem / grpc-spring

Spring Boot starter module for gRPC framework.
https://grpc-ecosystem.github.io/grpc-spring/
Apache License 2.0
3.48k stars 812 forks source link

Client Connection Status #481

Open alex-damico opened 3 years ago

alex-damico commented 3 years ago

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

Example:

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

Thank you for your support

ST-DDT commented 3 years ago

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

alex-damico commented 3 years ago

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

ST-DDT commented 3 years ago

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.

slogic commented 3 years ago

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.

ST-DDT commented 3 years ago

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?

slogic commented 3 years ago

I need it for deterministic deadline.

313hemant313 commented 1 year ago

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 ?