-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: finish triple helloworld example #612
Merged
chickenlj
merged 15 commits into
apache:new-triple-samples
from
DMwangnima:new-triple-samples-dev
Oct 27, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3c61f95
dubbo go shop framework
wudong5 97ae9e9
fix mod bug
wudong5 fa7f958
fix import bug
wudong5 b021d1c
add license
wudong5 8f256ba
add readme
wudong5 2fe8494
add readme
wudong5 0f60c33
merge
wudong5 facc2e4
fix merge
wudong5 b03daf8
add more version
wudong5 e83dbf3
Merge pull request #582 from wudong5/task_shop
chickenlj 7248d7c
feat: finish triple helloworld example
DMwangnima 6aed556
add zookeeper registry samples
DMwangnima deee3ca
Merge branch 'apache:master' into new-triple-samples-dev
DMwangnima 8f3038c
modify helloworld example
DMwangnima b7e8a3f
modify readme
DMwangnima File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,4 @@ jobs: | |
|
||
- name: Integration Test | ||
run: | | ||
./start_integrate_test.sh | ||
./start_integrate_test.sh |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,199 @@ | ||
# Helloworld for Dubbo-go 3.0 | ||
|
||
For api definition and go client and server startup, please refer to [dubbo-go 3.0 quickstart](https://dubbogo.github.io/zh-cn/docs/user/quickstart/3.0/quickstart.html) | ||
|
||
## Instructions | ||
1. Start zookeeper | ||
|
||
2. Start the server | ||
|
||
Use goland to start helloworld-go-server | ||
|
||
or | ||
|
||
Execute `sh run.sh` in the java-server folder to start the java server | ||
|
||
3. Start the client | ||
|
||
Use goland to start helloworld-go-client | ||
|
||
or | ||
|
||
Execute `sh run.sh` under the java-client folder to start the java client | ||
|
||
# Helloworld for dubbo-go Triple | ||
|
||
This is **Triple** helloworld example to help you finish a basic RPC invocation done quickly. | ||
|
||
## Prerequisites | ||
|
||
### install protoc | ||
|
||
#### install with package manager | ||
|
||
```shell | ||
# for Linux, use apt or apt-get | ||
apt install -y protobuf-compiler | ||
protoc --version # make sure that version is 3+ | ||
|
||
# for Macos, using homebrew | ||
brew install protobuf | ||
protoc --version # make sure that version is 3+ | ||
``` | ||
|
||
#### install pre-compiled binary | ||
|
||
```shell | ||
# fetch the pre-compiled protoc corresponding to your operating system and computer architecture | ||
# protoc-<version>-<os>-<arch>.zip | ||
# or you can download from github.com/protocolbuffers/protobuf/releases manually | ||
PB_REL="https://github.com/protocolbuffers/protobuf/releases" | ||
curl -LO $PB_REL/download/v24.4/protoc-24.4-linux-x86_64.zip | ||
|
||
# unzip downloaded file under a directory | ||
unzip protoc-24.4-linux-x86_64.zip -d $HOME/.local | ||
|
||
# update path variable | ||
export PATH="$PATH:$HOME/.local/bin" | ||
``` | ||
|
||
#### build protoc from sources | ||
|
||
Please see [**Download Protocol Buffers**](https://protobuf.dev/downloads/). | ||
|
||
### install protoc-gen-go | ||
|
||
```shell | ||
# install the version of your choice of protoc-gen-go. here use the latest version as example | ||
go install google.golang.org/protobuf/cmd/[email protected] | ||
``` | ||
|
||
### install protoc-gen-triple | ||
|
||
```shell | ||
# install the latest version of protoc-gen-triple | ||
git clone https://github.com/apache/dubbo-go.git && cd ./dubbo-go | ||
git checkout feature-triple | ||
go mod tidy | ||
cd ./protocol/triple/triple-tool/protoc-gen-triple | ||
go install . | ||
``` | ||
|
||
## Generate Triple stub code | ||
|
||
```shell | ||
mkdir ~/triple_helloworld && cd ~/triple_helloworld | ||
go mod init triple_helloworld | ||
mkdir proto && cd ./proto | ||
|
||
# replace this with your own proto IDL file | ||
cat > greet.proto << EOF | ||
syntax = "proto3"; | ||
|
||
package greet; | ||
|
||
option go_package = "triple_helloworld/proto;greet"; | ||
|
||
message GreetRequest { | ||
string name = 1; | ||
} | ||
|
||
message GreetResponse { | ||
string greeting = 1; | ||
} | ||
|
||
service GreetService { | ||
rpc Greet(GreetRequest) returns (GreetResponse) {} | ||
} | ||
|
||
EOF | ||
|
||
# generate related stub code with protoc-gen-go and protoc-gen-triple | ||
protoc --go_out=. --go_opt=paths=source_relative --triple_out=. --triple_opt=paths=source_relative ./greet.proto | ||
``` | ||
|
||
## Finish client and server code | ||
|
||
### client | ||
|
||
```shell | ||
cd ~/triple_helloworld | ||
mkdir -p go-client/cmd && cd ./go-client/cmd | ||
``` | ||
|
||
Finish **client.go** and put it in **go-client/cmd** directory. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"dubbo.apache.org/dubbo-go/v3/client" | ||
// important, must import this for dubbo-go extensions | ||
_ "dubbo.apache.org/dubbo-go/v3/imports" | ||
greet "triple_helloworld/proto" | ||
"triple_helloworld/proto/greettriple" | ||
"github.com/dubbogo/gost/log/logger" | ||
) | ||
|
||
func main() { | ||
// initialize a Client which is responsible for invoking a certain service. it uses Triple protocol by default | ||
// if you want to invoke another service, please initialize a new one | ||
cli, err := client.NewClient( | ||
// specify target server URL | ||
client.WithURL("127.0.0.1:20000"), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
svc, err := greettriple.NewGreetService(cli) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"}) | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
logger.Infof("Greet response: %s", resp.Greeting) | ||
} | ||
``` | ||
|
||
### server | ||
```shell | ||
cd ~/triple_helloworld | ||
mkdir -p go-server/cmd | ||
mkdir -p go-server/handler | ||
``` | ||
|
||
Implement **GreetService** Interface and put it in **go-server/handler** directory. | ||
Please refer to [**concrete sample**](https://github.com/apache/dubbo-go-samples/tree/new-triple-samples/helloworld/go-server/handler). | ||
|
||
Finish **server.go** and put it in **go-server/cmd** directory. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
// important, must import this for dubbo-go extensions | ||
_ "dubbo.apache.org/dubbo-go/v3/imports" | ||
"dubbo.apache.org/dubbo-go/v3/protocol" | ||
"dubbo.apache.org/dubbo-go/v3/server" | ||
"triple_helloworld/go-server/handler" | ||
"triple_helloworld/proto/greettriple" | ||
"github.com/dubbogo/gost/log/logger" | ||
) | ||
|
||
func main() { | ||
// initialize a Server for serving multiple services | ||
srv, err := server.NewServer( | ||
// use Triple protocol by default | ||
server.WithServerProtocol( | ||
// specify port to listen on | ||
protocol.WithPort(20000), | ||
), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// register a certain service | ||
if err := greettriple.RegisterGreetServiceHandler(srv, &handler.GreetTripleServer{}); err != nil { | ||
panic(err) | ||
} | ||
if err := srv.Serve(); err != nil { | ||
logger.Error(err) | ||
} | ||
} | ||
``` | ||
|
||
## Build and run | ||
|
||
```shell | ||
cd ~/triple_helloworld/go-server/cmd | ||
go build -o server . | ||
./server | ||
``` | ||
|
||
```shell | ||
cd ~/triple_helloworld/go-client/cmd | ||
go build -o client . | ||
./client | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename to
protoc-gen-triple-go
orprotoc-gen-go-triple
to follow the protoc plugin naming convention?