다른 언어간에 gRPC 사용 (server:golang, client:java)

4484 단어 gRPC
공식 튜토리얼을 참고해보세요
htps://grpc. 이오 / 드 cs / 쿠이 cks rt /

환경
$ go version
go version go1.12.4 darwin/amd64
$ java -version
java version "1.8.0_131"

서버

greeter_server/main.go
func (s *server) SayTestRpc(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
  log.Printf("Received: %v", in.Name)
  return &pb.HelloReply{Message: "This is go server rpc" + in.Name}, nil
}

클라이언트

src/main/java/io/grpc/examples/helloworld/HelloWorldClient.java
public void checkrpc(String name) {
  HelloRequest request = HelloRequest.newBuilder().setName(name).build();
  HelloReply response;
  try {
    response = blockingStub.sayTestRpc(request);
  } catch (StatusRuntimeException e) {
    logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
    return;
  }
  logger.info("Greeting: " + response.getMessage());
}

동작 확인
# server
$ go run greeter_server/main.go
# client
$ ./build/install/examples/bin/hello-world-client
〜省略〜 Greeting: This is go server rpcworld

http2에서 POST 중

좋은 웹페이지 즐겨찾기