获取GRPC的连接状态 [英] getting connection state for GRPC
问题描述
我正在尝试通过下面复制的调用来获取GRPC(Java API)连接的连接状态.根据我在网上可以找到的注释,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版本:1.1.2
JDK版本:1.8
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);
推荐答案
更新: getState(true)
在 grpc-java v1.11.0 (2018年3月30日).
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).
原始答案:
对于大多数 ManagedChannel
s.该API是为新的 LoadBalancer
API引入的,但现在甚至 LoadBalancer
都没有使用它.
It isn't currently implemented for most ManagedChannel
s. 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.
您对频道行为的理解是正确的.延迟连接,这是可以强制连接Channel的API.不幸的是,它尚未实现,除了发行RPC之外没有其他选择.
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.
这篇关于获取GRPC的连接状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!