gRPC示例的目的是跨语言通信吗?

huangapple go评论88阅读模式
英文:

Are the grpc examples intended to speak across languages?

问题

gRPC示例的目的是互操作吗?我可以完全使用Java运行Java客户端-服务器示例。我可以完全使用Go运行Go示例。但是Go的hello world客户端无法与Java的hello world服务器通信。

在一个终端中,从grpc-java运行以下命令:

$ ./gradlew :grpc-examples:helloWorldServer
:grpc-core:compileJava UP-TO-DATE
...
:grpc-examples:helloWorldServer
Mar 10, 2015 7:01:50 PM io.grpc.examples.helloworld.HelloWorldServer start
INFO: Server started, listening on 50051

Building 96% > :grpc-examples:helloWorldServer

在另一个终端中,从grpc-common/go运行以下命令:

$ go run greeter_client/main.go
2015/03/10 19:02:47 could not greet: rpc error: code = 12 desc = "Method not found: /helloworld.Greeter/SayHello"
exit status 1

这不是我期望的跨语言示例。SayHello是存在的,但问题是路径还是大小写敏感性?我是否遗漏了什么,或者这种跨语言合作是一个尚未实现的意图?

(注意-我不了解Go,并且我一直无法为C++构建grpc)。

英文:

Are the gRPC examples intended to interoperate? I can run the Java client-server examples entirely with Java. I can Go examples entirely with Go. But Go's hello world client won't talk with Java's hello world server.

In one terminal, from grpc-java:

$ ./gradlew :grpc-examples:helloWorldServer
:grpc-core:compileJava UP-TO-DATE
...
:grpc-examples:helloWorldServer
Mar 10, 2015 7:01:50 PM io.grpc.examples.helloworld.HelloWorldServer start
INFO: Server started, listening on 50051
> Building 96% > :grpc-examples:helloWorldServer

In another terminal, from grpc-common/go

$ go run greeter_client/main.go
2015/03/10 19:02:47 could not greet: rpc error: code = 12 desc = "Method not found: /helloworld.Greeter/SayHello"
exit status 1

Not the cross-language example I was expecting. SayHello is there, but is the problem with path or case sensitivity? Am I missing something, or is this cross-language cooperation an intent not yet realized?

(Caveat--I don't know Go, and I've been unable to build grpc for C++).

答案1

得分: 4

你正在使用的两个示例基于不兼容的proto定义。问题在于Java示例使用了包名grpc.example.helloworld,而Go示例只使用了helloworld

由于包名是URL路径的一部分(/helloworld.Greeter/SayHello),所以调用失败(Java服务器期望的是/grpc.example.helloworld.Greeter/SayHello)。

你可以在生成的代码中看到这一点。

Java:

private GreeterServiceDescriptor() {
  sayHello = createMethodDescriptor(
      "grpc.example.helloworld.Greeter", METHOD_SAY_HELLO);
}

Go:

var _Greeter_serviceDesc = grpc.ServiceDesc{
        ServiceName: "helloworld.Greeter",
        HandlerType: (*GreeterServer)(nil),
        Methods: []grpc.MethodDesc{
            {
                MethodName: "SayHello",
                Handler: _Greeter_SayHello_Handler,
            },
        },
        Streams: []grpc.StreamDesc{},
}
英文:

The two examples you are using are based on incompatible proto definitions. The problem is that the java example is using the package name grpc.example.helloworld and the go example is using just the helloworld.

And because the package name is part of the URL path (/helloworld.Greeter/SayHello) the call fails (the java server is expecting /grpc.example.helloworld.Greeter/SayHello).

You can see it in the generated code.

Java:

private GreeterServiceDescriptor() {
  sayHello = createMethodDescriptor(
      "grpc.example.helloworld.Greeter", METHOD_SAY_HELLO);
}

Go:

var _Greeter_serviceDesc = grpc.ServiceDesc{
        ServiceName: "helloworld.Greeter",
        HandlerType: (*GreeterServer)(nil),
        Methods: []grpc.MethodDesc{
            {
                MethodName: "SayHello",
                Handler: _Greeter_SayHello_Handler,
            },
        },
        Streams: []grpc.StreamDesc{},
}

huangapple
  • 本文由 发表于 2015年3月11日 07:18:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/28975841.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定