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:
The shared service definition is as follows. Please pay attention to the specific definitions of package
, go_package
, and java_package
:
//protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. greet.proto
syntax = "proto3";
package org.apache.dubbo.sample;
option go_package = "github.com/apache/dubbo-go-samples/java_interop/protobuf-triple/go/proto;proto";
//package of go
option java_package = 'org.apache.dubbo.sample';
option java_multiple_files = true;
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "WH";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello(HelloRequest) returns (HelloReply);
// Sends a greeting via stream
// rpc SayHelloStream (stream HelloRequest) returns (stream HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 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:
curl \
--header "Content-Type: application/json" \
--data '{"name": "Dubbo"}' \
http://localhost:50052/org.apache.dubbo.sample.Greeter/sayHello
Run the following command to start the java client and see the service call output from the go server:
./java/java-client/run.sh
Run the following command to start the java server:
Note: Please close the previously started go server to avoid port conflict.
./java/java-server/run.sh
You can test if the service runs normally with the following command:
curl \
--header "Content-Type: application/json" \
--data '{"name": "Dubbo"}' \
http://localhost:50052/org.apache.dubbo.sample.Greeter/sayHello
Run the following command to start the go client and see the service call output from the java server:
go run go/go-client/cmd/client.go