【问题标题】:Kotlin / Java grpc check connection statusKotlin / Java grpc 检查连接状态
【发布时间】:2020-05-06 15:52:38
【问题描述】:

我正在用 Kotlin 编写一个应用程序来连接到 grpc 服务器并获取数据。

下面是我的代码 sn-p :

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

stub = hello.HelloGrpc.newBlockingStub(channel)

我的 GRPC 服务器关闭,但我可以看到这两个变量的值如下:

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

我很困惑,如何检查连接是否未激活。

目前,我在获取值时添加了 try catch 语句,这会引发错误

不可用:io 异常

只是想知道,有什么方法可以检查我的连接状态并尝试重新连接以断开连接。

【问题讨论】:

标签: java kotlin grpc grpc-java


【解决方案1】:

gRPC automatically attempts re-connection,使用指数退避。继续使用频道,问题解决后错误就会消失。

如果您对Channel当前的连接状态感兴趣,可以使用ManagedChannel.getState()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 2013-08-17
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    • 2017-03-12
    • 2014-08-18
    相关资源
    最近更新 更多