doujia2090
2019-04-29 12:11
浏览 536
已采纳

如何为安全的go grpc服务创建不安全的Java grpc客户端

I am trying to create grpc service client in Java where server is in goLang and deployed with the https . where I am trying to achieve a non-secured connection [I don't want to pass the certificate ]

public class testgrpc {
    ManagedChannel channel ;
    ServiceGrpc.ServiceBlockingStub  blockingStub;
    String host = "remotesecuredhost";
    int port ="XXX";

    @Test
    public void testgrpc()
    {
    channel = ManagedChannelBuilder.forAddress(host,port).build();

     blockingStub = ServiceGrpc.newBlockingStub(channel);

    response =  blockingStub.health(Empty.newBuilder().build());

    }

}

the above code gives following exception

io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
    at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:221)
    at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:202)
    at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:131)

can someone help with Client code

图片转代码服务由CSDN问答提供 功能建议

我正在尝试用Java创建grpc服务客户端,其中服务器位于goLang中,并使用https进行部署。 我试图建立非安全连接的位置[我不想通过证书] </ p>

 公共类testgrpc {
 ManagedChannel channel; 
 ServiceGrpc.ServiceBlockingStub  BlockingStub; 
字符串host =“ remotesecuredhost”; 
 int port =“ XXX”; 
 
 @Test 
 public void testgrpc()
 {
 channel = ManagedChannelBuilder.forAddress(host,port).build  (); 
 
blockingStub = ServiceGrpc.newBlockingStub(channel); 
 
 response = blockingStub.health(Empty.newBuilder()。build()); 
 
} 
 
} 
 <  / code> </ pre> 
 
 

上面的代码给出了以下异常</ p>

  io.grpc.StatusRuntimeException:不可用:io异常
在io.grpc  .stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:221)
在io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:202)
在io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:131  )
 </ code> </ pre> 
 
 

有人可以帮助客户代码</ p> </ div>

3条回答 默认 最新

相关推荐 更多相似问题