You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/09/07 06:24:32 UTC
[dubbo-go-samples] branch config-enhance updated: Restore
grpc-server sample (#228)
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch config-enhance
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
The following commit(s) were added to refs/heads/config-enhance by this push:
new 4d8c190 Restore grpc-server sample (#228)
4d8c190 is described below
commit 4d8c19062c55eadd4da3f34d146edcdd41de39f5
Author: XavierNiu <a...@nxw.name>
AuthorDate: Tue Sep 7 14:24:13 2021 +0800
Restore grpc-server sample (#228)
* update docs
* refactor rpc/triple/pb/dubbogo-grpc
* integrated test for dubbogo-grpc
* unify proto file
* fix import paths
* resolve proto namespace conflict
* adjust directory structure
* adjust to standard dir structure
* adjust integrated test name of dubbogo-rpc
* adjust to standard dir structure
* reopen all integrated tests
* add run.xml
* restore grpc-server sample
Co-authored-by: niuxuewei.xavier <ni...@bytedance.com>
---
rpc/triple/README.md | 4 +-
rpc/triple/pb/dubbogo-grpc/README.md | 12 ++--
rpc/triple/pb/dubbogo-grpc/grpc-server/main.go | 93 ++++++++++++++++++++++++++
start_integrate_test.sh | 5 +-
4 files changed, 103 insertions(+), 11 deletions(-)
diff --git a/rpc/triple/README.md b/rpc/triple/README.md
index ef9fe22..922bb1e 100644
--- a/rpc/triple/README.md
+++ b/rpc/triple/README.md
@@ -5,8 +5,8 @@ Triple-go is a network protocol library released in version 3.0 based on the exi
## Contents
- [codec-extension](./codec-extension): TODO: ~~code-extension~~
-- [hessian2](./hessian2): TODO: ~~hessian2 introduction~~
+- [hessian2](./hessian2): A Triple sample using hessian2 serialization.
- [msgpack](./msgpack): TODO: ~~msgpack introduction~~
-- [pb](./pb): Triple samples using ProtoBuf(PB) serialization
+- [pb](./pb): Triple samples using ProtoBuf(PB) serialization.
- [dubbogo-grpc](./pb/dubbogo-grpc): Samples for communication between Dubbo-go using triple protocol and original gRPC(triple-go <-> grpc).
- [dubbogo-java](./pb/dubbogo-java): Samples for communication between Dubbo-go and Dubbo-java using Triple protocol(triple-go <-> triple-java).
diff --git a/rpc/triple/pb/dubbogo-grpc/README.md b/rpc/triple/pb/dubbogo-grpc/README.md
index 5744fe7..0464143 100644
--- a/rpc/triple/pb/dubbogo-grpc/README.md
+++ b/rpc/triple/pb/dubbogo-grpc/README.md
@@ -3,14 +3,14 @@
## Contents
- protobuf: proto files for grpc and triple respectively;
-- dubbogo-server
-- dubbogo-client
-- grpcgo-server
-- grpcgo-client
+- go-server: Dubbo-go server
+- go-client: Dubbo-go client
+- grpc-server: gRPC server
+- grpc-client: gRPC client
Please note that neither server streaming RPC nor client streaming RPC are not supported by Triple so far.
-What combination we tested are:
+What combinations we tested are:
- [x] grpcgo-client -> dubbogo-server
- [x] dubbogo-client -> dubbogo-server
@@ -19,7 +19,7 @@ What combination we tested are:
### Server
-1. Edit your own proto file, please refer to [helloworld.proto](./protobuf/triple/helloworld.proto).
+1. Edit your own proto file, please refer to [samples_api.proto](/api/samples_api.proto).
2. Install `protoc` tool, please refer to [ProtoBuf documentation](https://developers.google.com/protocol-buffers/docs/gotutorial).
3. Install `protoc-gen-dubbo3` which is used to generate a stub suitable for triple.
diff --git a/rpc/triple/pb/dubbogo-grpc/grpc-server/main.go b/rpc/triple/pb/dubbogo-grpc/grpc-server/main.go
new file mode 100644
index 0000000..d996c2d
--- /dev/null
+++ b/rpc/triple/pb/dubbogo-grpc/grpc-server/main.go
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "fmt"
+ "log"
+ "net"
+)
+
+import (
+ "github.com/dubbogo/net/context"
+
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/reflection"
+)
+
+import (
+ pb "github.com/apache/dubbo-go-samples/rpc/triple/pb/dubbogo-grpc/protobuf/grpc"
+)
+
+const (
+ port = ":20000"
+)
+
+// GreeterProvider is used as provider
+type GreeterProvider struct{
+ pb.UnimplementedGreeterServer
+}
+
+func (s *GreeterProvider) SayHelloStream(svr pb.Greeter_SayHelloStreamServer) error {
+ c, err := svr.Recv()
+ if err != nil {
+ return err
+ }
+ fmt.Printf("grpc GreeterProvider recv 1 user, name = %s\n", c.Name)
+ c2, err := svr.Recv()
+ if err != nil {
+ return err
+ }
+ fmt.Printf("grpc GreeterProvider recv 2 user, name = %s\n", c2.Name)
+
+ svr.Send(&pb.User{
+ Name: "hello " + c.Name,
+ Age: 18,
+ Id: "123456789",
+ })
+ c3, err := svr.Recv()
+ if err != nil {
+ return err
+ }
+ fmt.Printf("grpc GreeterProvider recv 3 user, name = %s\n", c3.Name)
+ svr.Send(&pb.User{
+ Name: "hello " + c2.Name,
+ Age: 19,
+ Id: "123456789",
+ })
+ return nil
+}
+
+func (s *GreeterProvider) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.User, error) {
+ fmt.Printf("Dubbo3 GreeterProvider get user name = %s\n" + in.Name)
+ return &pb.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
+}
+
+func main() {
+ lis, err := net.Listen("tcp", port)
+ if err != nil {
+ log.Fatalf("failed to listen: %v", err)
+ }
+ s := grpc.NewServer()
+ pb.RegisterGreeterServer(s, &GreeterProvider{})
+ // Register reflection service on gRPC client.
+ reflection.Register(s)
+ if err := s.Serve(lis); err != nil {
+ log.Fatalf("failed to serve: %v", err)
+ }
+}
\ No newline at end of file
diff --git a/start_integrate_test.sh b/start_integrate_test.sh
index d62de45..a13326c 100755
--- a/start_integrate_test.sh
+++ b/start_integrate_test.sh
@@ -94,6 +94,8 @@ array=("helloworld")
array+=("direct")
# config-api
array+=("config-api/rpc/triple")
+array+=("config-api/configcenter/nacos")
+array+=("config-api/configcenter/zookeeper")
# registry
array+=("registry/zookeeper")
array+=("registry/nacos")
@@ -102,9 +104,6 @@ array+=("rpc/triple/codec-extension")
array+=("rpc/triple/hessian2")
array+=("rpc/triple/pb/dubbogo-grpc")
-array+=("config-api/configcenter/nacos")
-array+=("config-api/configcenter/zookeeper")
-
for((i=0;i<${#array[*]};i++))
do
./integrate_test.sh "${array[i]}"