English | 中文
This example demonstrates the basic usage of dubbo-go as an RPC framework, and shows Dubbo-Go with Java Interoperability. Check Quick Start on our official website for detailed explanation.
- go-server/cmd/main.go - is the main definition of the service, handler and rpc server
- go-client/cmd/main.go - is the rpc client
- java-server/src/main/java/org/example/server/JavaServerApp.java - is the Java server
- java-client/src/main/java/org/example/client/JavaClientApp.java - is the Java client
- proto - shared protobuf definition used by both Go and Java modules
-
Install
protocversion3 Please refer to Protocol Buffer Compiler Installation. -
Install
protoc-gen-goandprotoc-gen-tripleInstall the version of your choice of protoc-gen-go. here use the latest version as example:go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31
Install the latest version of protoc-gen-triple:
go install github.com/dubbogo/protoc-gen-go-triple/v3@v3.0.2
-
Generate stub code
Generate related stub code with protoc-gen-go and protoc-gen-go-triple:
protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. --go-triple_opt=paths=source_relative ./proto/greet.proto
-
Install
MavenMaven
go run ./go-server/cmd/main.gotest server work as expected:
curl \
--header "Content-Type: application/json" \
--data '{"name": "Dubbo"}' \
http://localhost:20000/greet.GreetService/Greetgo run ./go-client/cmd/main.goBuild all Java modules from the root directory:
mvn clean compileRun the Java server:
On Linux/Mac/Git Bash:
cd java-server
mvn exec:java -Dexec.mainClass=org.example.server.JavaServerAppOn Windows PowerShell:
cd java-server
mvn exec:java "-Dexec.mainClass=org.example.server.JavaServerApp"Or use the provided script (Linux/Mac):
cd java-server
./run.shTest server works as expected:
curl \
--header "Content-Type: application/json" \
--data '{"name": "Dubbo"}' \
http://localhost:20000/greet.GreetService/GreetRun the Java client:
On Linux/Mac/Git Bash:
cd java-client
mvn exec:java -Dexec.mainClass=org.example.client.JavaClientAppOn Windows PowerShell:
cd java-client
mvn exec:java "-Dexec.mainClass=org.example.client.JavaClientApp"Or use the provided script (Linux/Mac):
cd java-client
./run.shDo NOT Start Go Server and Java Server at the Same Time. Both the Go server and Java server listen on the same port: 20000 and expose the same Triple service path:greet.GreetService/Greet