Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Helloworld for dubbo-go

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.

Contents

  • 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

How to run

Prerequisites

  1. Install protoc version3 Please refer to Protocol Buffer Compiler Installation.

  2. Install protoc-gen-go and protoc-gen-triple Install 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
  3. 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
  4. Install Maven Maven

Run Golang server

go run ./go-server/cmd/main.go

test server work as expected:

curl \
    --header "Content-Type: application/json" \
    --data '{"name": "Dubbo"}' \
    http://localhost:20000/greet.GreetService/Greet

Run Golang client

go run ./go-client/cmd/main.go

Run Java server

Build all Java modules from the root directory:

mvn clean compile

Run the Java server:

On Linux/Mac/Git Bash:

cd java-server
mvn exec:java -Dexec.mainClass=org.example.server.JavaServerApp

On 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.sh

Test server works as expected:

curl \
    --header "Content-Type: application/json" \
    --data '{"name": "Dubbo"}' \
    http://localhost:20000/greet.GreetService/Greet

Run Java client

Run the Java client:

On Linux/Mac/Git Bash:

cd java-client
mvn exec:java -Dexec.mainClass=org.example.client.JavaClientApp

On 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.sh

Attention

Do 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