0
votes

I am writing one app in Kotlin to connect to grpc server and fetch data.

Below is my code snippet :

channel = ManagedChannelBuilder.forTarget("localhost:25001")
                .usePlaintext()
                .build()

stub = hello.HelloGrpc.newBlockingStub(channel)

My GRPC Server is down, but i can see value for both variable as below :

for channel = channelManagedChannelOrphanWrapper{delegate=ManagedChannelImpl{logId=1, target=localhost:25001}}
for stub = channelhello.HelloGrpc$HelloBlockingStub@19b843ba

I am confused, how to check if connection is not active.

For now, i have added try catch statement while fetching value, which is throwing me an error

UNAVAILABLE: io exception

Just wondering, Is there any way by which I can check my connection status and try to re-connect for broken connection.

1

1 Answers

1
votes

gRPC automatically attempts re-connection, using exponential backoff. Just continue using the Channel and the errors will go away when the issue is resolved.

If you are interested in the current connectivity status of the Channel, you can use ManagedChannel.getState().