英文:
GRPC ConnectivityState is not working true?
问题
ManagedChannel managedChannel = ManagedChannelBuilder
.forAddress("localhost", 9090)
.usePlaintext().build();
System.out.println("State: " + managedChannel.getState(false)) // State: IDLE
Grpc.Stub stub = Grpc.newStub(managedChannel);
System.out.println("State: " + managedChannel.getState(false)) // State: IDLE
stub.callMethod();
System.out.println("State: " + managedChannel.getState(false)) // State: IDLE
以上代码是 GRPC 客户端代码。它与 GRPC 服务器建立连接。但每次通道状态都是 IDLE?什么时候是 CONNECTING 和 READY 状态?有什么问题吗?
英文:
ManagedChannel managedChannel = ManagedChannelBuilder
.forAddress("localhost", 9090)
.usePlaintext().build();
System.out.println("State: " + managedChannel .getState(false)) // State: IDLE
Grpc.Stub stub = Grpc.newStub(managedChannel);
System.out.println("State: " + managedChannel .getState(false)) // State: IDLE
stub.callMethod();
System.out.println("State: " + managedChannel .getState(false)) // State: IDLE
Above code is GRPC client. It get connection with grpc server. But every time the channel state is IDLE? When is CONNECTING and READY state? Whats wrong?
答案1
得分: 1
需要等待另一种状态。
当服务器未启动时,以下代码会打印connection state: TRANSIENT_FAILURE
,当服务器健康时会打印connection state: READY
。
gRPC版本:1.24.0
ManagedChannel managedChannel = ManagedChannelBuilder
.forAddress("localhost", 9090)
.usePlaintext().build();
ConnectivityState state = channel.getState(true);
while (state == ConnectivityState.IDLE || state == ConnectivityState.CONNECTING) {
state = channel.getState(true);
}
System.out.println("connection state: " + state.toString());
英文:
It is required to wait for another state.
The following code prints connection state: TRANSIENT_FAILURE
when server is not started and connection state: READY
when it is healthy.
gRPC version: 1.24.0
ManagedChannel managedChannel = ManagedChannelBuilder
.forAddress("localhost", 9090)
.usePlaintext().build();
ConnectivityState state = channel.getState(true);
while (state == ConnectivityState.IDLE || state == ConnectivityState.CONNECTING) {
state = channel.getState(true);
}
System.out.println("connection state: " + state.toString());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论