代码模型看起来像
Iterator iterator = grpc.invokeSomeRequest(requestData) //returns iterator
while(iterator.hasNext()){
//do some code.
}
有时错误发生在
iterator.hasNext()
,并带有堆栈跟踪:
UNAVAILABLE: io exception
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
at io.grpc.Status.asRuntimeException(Status.java:533)
grpc的版本是1.21.0
我发现这个问题最有可能出现在 grpc 上。我可能是错的。 解决此问题的最佳方法是什么?
对我来说,当我使用时,这个问题就解决了
channelBuilder = NettyChannelBuilder.forAddress(host, port).usePlaintext().enableRetry().keepAliveTime(10,TimeUnit.SECONDS);
而不是
channelBuilder = NettyChannelBuilder.forAddress(host, port);
channelBuilder.negotiationType(NegotiationType.TLS).enableRetry().keepAliveTime(10,TimeUnit.SECONDS);
channelBuilder.sslContext(
GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build())