Intercommunication of the triple protocol based on protobuf (suitable for scenarios developed with protobuf on both sides)

“Realization of intercommunication between dubbo-java and dubbo-go using the triple protocol based on protobuf.”

Here we provide an example demonstrating how to implement intercommunication between dubbo-java and dubbo-go using the triple protocol. The complete source code can be viewed here.

The main content of the example is as follows:

  • Go: RPC server and client implemented in Go
  • Java: RPC server and client implemented in Java

Shared protobuf service definition

The shared service definition is as follows. Please pay attention to the specific definitions of package, go_package, and java_package:

  1. //protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. greet.proto
  2. syntax = "proto3";
  3. package org.apache.dubbo.sample;
  4. option go_package = "github.com/apache/dubbo-go-samples/java_interop/protobuf-triple/go/proto;proto";
  5. //package of go
  6. option java_package = 'org.apache.dubbo.sample';
  7. option java_multiple_files = true;
  8. option java_outer_classname = "HelloWorldProto";
  9. option objc_class_prefix = "WH";
  10. // The greeting service definition.
  11. service Greeter {
  12. // Sends a greeting
  13. rpc SayHello(HelloRequest) returns (HelloReply);
  14. // Sends a greeting via stream
  15. // rpc SayHelloStream (stream HelloRequest) returns (stream HelloReply) {}
  16. }
  17. // The request message containing the user's name.
  18. message HelloRequest {
  19. string name = 1;
  20. }
  21. // The response message containing the greetings
  22. message HelloReply {
  23. string message = 1;
  24. }

java-client calls go-server

  1. First, start the go server:
  1. go run go/go-server/cmd/server.go

After running the above command, the go server runs on port 50052. You can test if the service runs normally with the following command:

  1. curl \
  2. --header "Content-Type: application/json" \
  3. --data '{"name": "Dubbo"}' \
  4. http://localhost:50052/org.apache.dubbo.sample.Greeter/sayHello
  1. Start the java client

Run the following command to start the java client and see the service call output from the go server:

  1. ./java/java-client/run.sh

go-client calls java-server

  1. Start the java server

Run the following command to start the java server:

Note: Please close the previously started go server to avoid port conflict.

  1. ./java/java-server/run.sh

You can test if the service runs normally with the following command:

  1. curl \
  2. --header "Content-Type: application/json" \
  3. --data '{"name": "Dubbo"}' \
  4. http://localhost:50052/org.apache.dubbo.sample.Greeter/sayHello
  1. Run the go client

Run the following command to start the go client and see the service call output from the java server:

  1. go run go/go-client/cmd/client.go

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)