You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2021/09/04 15:57:39 UTC
[dubbo-go-samples] 07/12: fix: add grpc provider reference in codes
generated by protoc-gen-dubbo (#127)
This is an automated email from the ASF dual-hosted git repository.
zhaoyunxing pushed a commit to branch compress
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
commit f19f6f61a2b7490415a0fe6c73a594e1c4fdeed4
Author: Laurence <45...@users.noreply.github.com>
AuthorDate: Fri Jun 11 19:14:01 2021 +0800
fix: add grpc provider reference in codes generated by protoc-gen-dubbo (#127)
* fix: add grpc provider reference
* fix: fix grpc intergration test
---
general/grpc/go-client/cmd/client.go | 10 ++--
general/grpc/go-client/conf/client.yml | 2 +-
general/grpc/go-client/pkg/hello.go | 36 ---------------
general/grpc/go-server/cmd/server.go | 5 +-
general/grpc/go-server/conf/client.yml | 2 +-
general/grpc/go-server/conf/server.yml | 2 +-
general/grpc/go-server/pkg/greeter.go | 4 --
.../go-server/tests/integration/greeter_test.go | 10 +++-
.../grpc/go-server/tests/integration/main_test.go | 21 ++-------
general/grpc/protobuf/helloworld.pb.go | 8 +++-
general/grpc/stream/go-client/app/client.go | 7 ++-
general/grpc/stream/go-client/app/hello.go | 50 --------------------
general/grpc/stream/go-client/app/helloworld.pb.go | 4 ++
.../grpc/stream/go-client/profiles/dev/client.yml | 46 +++++++++---------
.../grpc/stream/go-client/profiles/test/client.yml | 42 ++++++++---------
general/grpc/stream/go-server/app/greeter.go | 4 --
general/grpc/stream/go-server/app/helloworld.pb.go | 4 ++
.../grpc/stream/go-server/profiles/dev/server.yml | 36 +++++++--------
.../stream/go-server/profiles/release/server.yml | 35 +++++++-------
.../grpc/stream/go-server/profiles/test/server.yml | 8 ++--
general/grpc/unary/go-client/app/client.go | 10 ++--
general/grpc/unary/go-client/app/hello.go | 43 -----------------
general/grpc/unary/go-client/app/helloworld.pb.go | 23 +++++----
general/grpc/unary/go-client/app/helloworld.proto | 4 +-
.../grpc/unary/go-client/profiles/dev/client.yml | 2 +-
.../unary/go-client/profiles/release/client.yml | 2 +-
.../grpc/unary/go-client/profiles/test/client.yml | 2 +-
general/grpc/unary/go-server/app/greeter.go | 15 ++----
general/grpc/unary/go-server/app/helloworld.pb.go | 54 ++++++++++++----------
.../grpc/unary/go-server/profiles/dev/server.yml | 2 +-
.../unary/go-server/profiles/release/server.yml | 2 +-
.../grpc/unary/go-server/profiles/test/server.yml | 2 +-
go.sum | 1 +
33 files changed, 183 insertions(+), 315 deletions(-)
diff --git a/general/grpc/go-client/cmd/client.go b/general/grpc/go-client/cmd/client.go
index a22f23a..919c92c 100644
--- a/general/grpc/go-client/cmd/client.go
+++ b/general/grpc/go-client/cmd/client.go
@@ -19,9 +19,6 @@ package main
import (
"context"
- "github.com/apache/dubbo-go-samples/general/grpc/go-client/pkg"
- "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
- "github.com/dubbogo/gost/log"
"time"
)
@@ -35,9 +32,14 @@ import (
_ "github.com/apache/dubbo-go/protocol/grpc"
_ "github.com/apache/dubbo-go/registry/protocol"
_ "github.com/apache/dubbo-go/registry/zookeeper"
+ "github.com/dubbogo/gost/log"
+)
+
+import (
+ "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
)
-var grpcGreeterImpl = new(pkg.GrpcGreeterImpl)
+var grpcGreeterImpl = new(protobuf.GreeterClientImpl)
func init() {
config.SetConsumerService(grpcGreeterImpl)
diff --git a/general/grpc/go-client/conf/client.yml b/general/grpc/go-client/conf/client.yml
index e440222..9342221 100644
--- a/general/grpc/go-client/conf/client.yml
+++ b/general/grpc/go-client/conf/client.yml
@@ -25,7 +25,7 @@ registries:
# reference config
references:
- "GrpcGreeterImpl":
+ "greeterImpl":
registry: "demoZk"
protocol: "grpc"
interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
diff --git a/general/grpc/go-client/pkg/hello.go b/general/grpc/go-client/pkg/hello.go
deleted file mode 100644
index d133e1f..0000000
--- a/general/grpc/go-client/pkg/hello.go
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 pkg
-
-import (
- "context"
- "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
- "google.golang.org/grpc"
-)
-
-type GrpcGreeterImpl struct {
- SayHello func(ctx context.Context, in *protobuf.HelloRequest, out *protobuf.HelloReply) error
-}
-
-func (u *GrpcGreeterImpl) Reference() string {
- return "GrpcGreeterImpl"
-}
-
-func (u *GrpcGreeterImpl) GetDubboStub(cc *grpc.ClientConn) protobuf.GreeterClient {
- return protobuf.NewGreeterClient(cc)
-}
diff --git a/general/grpc/go-server/cmd/server.go b/general/grpc/go-server/cmd/server.go
index b4d9875..984fcc5 100644
--- a/general/grpc/go-server/cmd/server.go
+++ b/general/grpc/go-server/cmd/server.go
@@ -19,7 +19,6 @@ package main
import (
"fmt"
- "github.com/apache/dubbo-go-samples/general/grpc/go-server/pkg"
"os"
"os/signal"
"syscall"
@@ -38,6 +37,10 @@ import (
_ "github.com/apache/dubbo-go/registry/zookeeper"
)
+import(
+ "github.com/apache/dubbo-go-samples/general/grpc/go-server/pkg"
+)
+
var (
survivalTimeout = int(3 * time.Second)
)
diff --git a/general/grpc/go-server/conf/client.yml b/general/grpc/go-server/conf/client.yml
index 615cd74..53ac35c 100644
--- a/general/grpc/go-server/conf/client.yml
+++ b/general/grpc/go-server/conf/client.yml
@@ -25,7 +25,7 @@ registries:
# reference config
references:
- "GrpcGreeterImpl":
+ "greeterImpl":
registry: "demoZk"
protocol: "grpc"
interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
diff --git a/general/grpc/go-server/conf/server.yml b/general/grpc/go-server/conf/server.yml
index 083bdd9..6cf6d5d 100644
--- a/general/grpc/go-server/conf/server.yml
+++ b/general/grpc/go-server/conf/server.yml
@@ -17,7 +17,7 @@ registries:
# service config
services:
- "GrpcGreeterImpl":
+ "greeterImpl":
registry: "zk"
protocol: "grpc"
interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
diff --git a/general/grpc/go-server/pkg/greeter.go b/general/grpc/go-server/pkg/greeter.go
index 7f26eb0..154d35d 100644
--- a/general/grpc/go-server/pkg/greeter.go
+++ b/general/grpc/go-server/pkg/greeter.go
@@ -37,7 +37,3 @@ func (g *GreeterProvider) SayHello(ctx context.Context, req *protobuf.HelloReque
fmt.Printf("req: %v", req)
return &protobuf.HelloReply{Message: "this is message from reply"}, nil
}
-
-func (g *GreeterProvider) Reference() string {
- return "GrpcGreeterImpl"
-}
diff --git a/general/grpc/go-server/tests/integration/greeter_test.go b/general/grpc/go-server/tests/integration/greeter_test.go
index 23c30d5..45eccdd 100644
--- a/general/grpc/go-server/tests/integration/greeter_test.go
+++ b/general/grpc/go-server/tests/integration/greeter_test.go
@@ -21,11 +21,17 @@ package integration
import (
"context"
- "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
- "github.com/stretchr/testify/assert"
"testing"
)
+import(
+ "github.com/stretchr/testify/assert"
+)
+
+import (
+ "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
+)
+
func TestGreeter(t *testing.T) {
reply := &protobuf.HelloReply{}
req := &protobuf.HelloRequest{
diff --git a/general/grpc/go-server/tests/integration/main_test.go b/general/grpc/go-server/tests/integration/main_test.go
index 909161a..74a9c4a 100644
--- a/general/grpc/go-server/tests/integration/main_test.go
+++ b/general/grpc/go-server/tests/integration/main_test.go
@@ -20,10 +20,6 @@
package integration
import (
- "context"
- "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
- "google.golang.org/grpc"
-
_ "github.com/apache/dubbo-go/cluster/cluster_impl"
_ "github.com/apache/dubbo-go/cluster/loadbalance"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
@@ -40,8 +36,11 @@ import (
"testing"
"time"
)
+import (
+ "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
+)
-var grpcGreeterImpl = new(GrpcGreeterImpl)
+var grpcGreeterImpl = new(protobuf.GreeterClientImpl)
func TestMain(m *testing.M) {
config.SetConsumerService(grpcGreeterImpl)
@@ -50,15 +49,3 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}
-
-type GrpcGreeterImpl struct {
- SayHello func(ctx context.Context, in *protobuf.HelloRequest, out *protobuf.HelloReply) error
-}
-
-func (u *GrpcGreeterImpl) Reference() string {
- return "GrpcGreeterImpl"
-}
-
-func (u *GrpcGreeterImpl) GetDubboStub(cc *grpc.ClientConn) protobuf.GreeterClient {
- return protobuf.NewGreeterClient(cc)
-}
diff --git a/general/grpc/protobuf/helloworld.pb.go b/general/grpc/protobuf/helloworld.pb.go
index fe0c3c8..8124c8f 100644
--- a/general/grpc/protobuf/helloworld.pb.go
+++ b/general/grpc/protobuf/helloworld.pb.go
@@ -243,6 +243,10 @@ func (s *GreeterProviderBase) GetProxyImpl() protocol.Invoker {
return s.proxyImpl
}
+func (c *GreeterProviderBase) Reference() string {
+ return "greeterImpl"
+}
+
func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HelloRequest)
if err := dec(in); err != nil {
@@ -253,7 +257,7 @@ func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec f
args = append(args, in)
invo := invocation.NewRPCInvocation("SayHello", args, nil)
if interceptor == nil {
- result := base.GetProxyImpl().Invoke(context.Background(), invo)
+ result := base.GetProxyImpl().Invoke(ctx, invo)
return result.Result(), result.Error()
}
info := &grpc.UnaryServerInfo{
@@ -261,7 +265,7 @@ func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec f
FullMethod: "/protobuf.Greeter/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
- result := base.GetProxyImpl().Invoke(context.Background(), invo)
+ result := base.GetProxyImpl().Invoke(ctx, invo)
return result.Result(), result.Error()
}
return interceptor(ctx, in, info, handler)
diff --git a/general/grpc/stream/go-client/app/client.go b/general/grpc/stream/go-client/app/client.go
index b2431b9..ede6be7 100644
--- a/general/grpc/stream/go-client/app/client.go
+++ b/general/grpc/stream/go-client/app/client.go
@@ -28,7 +28,6 @@ import (
import (
_ "github.com/apache/dubbo-go/cluster/cluster_impl"
- gxlog "github.com/dubbogo/gost/log"
_ "github.com/apache/dubbo-go/cluster/loadbalance"
"github.com/apache/dubbo-go/common/logger"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
@@ -38,11 +37,17 @@ import (
_ "github.com/apache/dubbo-go/protocol/grpc"
_ "github.com/apache/dubbo-go/registry/protocol"
_ "github.com/apache/dubbo-go/registry/zookeeper"
+ gxlog "github.com/dubbogo/gost/log"
)
var (
survivalTimeout int = 10e9
)
+var grpcGreeterImpl = new(GreeterClientImpl)
+
+func init() {
+ config.SetConsumerService(grpcGreeterImpl)
+}
// they are necessary:
// export CONF_CONSUMER_FILE_PATH="xxx"
diff --git a/general/grpc/stream/go-client/app/hello.go b/general/grpc/stream/go-client/app/hello.go
deleted file mode 100644
index 1066565..0000000
--- a/general/grpc/stream/go-client/app/hello.go
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 (
- "context"
-)
-
-import (
- "google.golang.org/grpc"
-)
-
-import (
- "github.com/apache/dubbo-go/config"
-)
-
-var grpcGreeterImpl = new(GrpcGreeterImpl)
-
-func init() {
- config.SetConsumerService(grpcGreeterImpl)
-}
-
-type GrpcGreeterImpl struct {
- SayHelloTwoSidesStream func(ctx context.Context) (Greeter_SayHelloTwoSidesStreamClient, error)
- SayHelloClientStream func(ctx context.Context) (Greeter_SayHelloClientStreamClient, error)
- SayHelloServerStream func(ctx context.Context, request *HelloRequest) (Greeter_SayHelloServerStreamClient, error)
-}
-
-func (u *GrpcGreeterImpl) Reference() string {
- return "GrpcGreeterImpl"
-}
-
-func (u *GrpcGreeterImpl) GetDubboStub(cc *grpc.ClientConn) GreeterClient {
- return NewGreeterClient(cc)
-}
diff --git a/general/grpc/stream/go-client/app/helloworld.pb.go b/general/grpc/stream/go-client/app/helloworld.pb.go
index 2183a4f..4bdfb1e 100644
--- a/general/grpc/stream/go-client/app/helloworld.pb.go
+++ b/general/grpc/stream/go-client/app/helloworld.pb.go
@@ -413,6 +413,10 @@ func (s *GreeterProviderBase) GetProxyImpl() protocol.Invoker {
return s.proxyImpl
}
+func (c *GreeterProviderBase) Reference() string {
+ return "greeterImpl"
+}
+
func _DUBBO_Greeter_SayHelloTwoSidesStream_Handler(srv interface{}, stream grpc.ServerStream) error {
_, ok := srv.(dgrpc.DubboGrpcService)
invo := invocation.NewRPCInvocation("SayHelloTwoSidesStream", nil, nil)
diff --git a/general/grpc/stream/go-client/profiles/dev/client.yml b/general/grpc/stream/go-client/profiles/dev/client.yml
index b2bc054..53ac35c 100644
--- a/general/grpc/stream/go-client/profiles/dev/client.yml
+++ b/general/grpc/stream/go-client/profiles/dev/client.yml
@@ -1,42 +1,40 @@
# dubbo client yaml configure file
-
check: true
# client
-request_timeout : "3s"
+request_timeout: "3s"
# connect timeout
-connect_timeout : "3s"
+connect_timeout: "3s"
# application config
application:
- organization : "ikurento.com"
- name : "BDTService"
- module : "dubbogo say-hello client"
- version : "0.0.1"
- owner : "ZX"
- environment : "dev"
-
-registries :
- "zk":
+ organization: "dubbo.io"
+ name: "GreeterGrpcTest"
+ module: "dubbo-go greeter grpc client"
+ version: "0.0.1"
+ environment: "dev"
+
+# registry config
+registries:
+ "demoZk":
protocol: "zookeeper"
- timeout : "3s"
+ timeout: "3s"
address: "127.0.0.1:2181"
username: ""
password: ""
-
+# reference config
references:
- "GrpcGreeterImpl":
- # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
- registry: "zk"
- protocol : "grpc"
- interface : "io.grpc.examples.helloworld.GreeterGrpc$IGreeter"
+ "greeterImpl":
+ registry: "demoZk"
+ protocol: "grpc"
+ interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
cluster: "failover"
- methods :
- - name: "SayHello"
- retries: 3
-
+ methods:
+ - name: "SayHello"
+ retries: 3
+# protocol config
protocol_conf:
grpc:
reconnect_interval: 0
@@ -58,4 +56,4 @@ protocol_conf:
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 10240
- session_name: "client"
\ No newline at end of file
+ session_name: "client"
diff --git a/general/grpc/stream/go-client/profiles/test/client.yml b/general/grpc/stream/go-client/profiles/test/client.yml
index e0c0737..53ac35c 100644
--- a/general/grpc/stream/go-client/profiles/test/client.yml
+++ b/general/grpc/stream/go-client/profiles/test/client.yml
@@ -1,45 +1,40 @@
# dubbo client yaml configure file
-
check: true
# client
-request_timeout : "3s"
+request_timeout: "3s"
# connect timeout
-connect_timeout : "3s"
-
-config_center:
- protocol: "zookeeper"
- address: "127.0.0.1:2181"
+connect_timeout: "3s"
# application config
application:
- organization : "ikurento.com"
- name : "BDTService"
- module : "dubbogo say-hello client"
- version : "0.0.1"
- owner : "ZX"
- environment : "dev"
-
-registries :
+ organization: "dubbo.io"
+ name: "GreeterGrpcTest"
+ module: "dubbo-go greeter grpc client"
+ version: "0.0.1"
+ environment: "dev"
+
+# registry config
+registries:
"demoZk":
protocol: "zookeeper"
- timeout : "3s"
+ timeout: "3s"
address: "127.0.0.1:2181"
username: ""
password: ""
+# reference config
references:
- "GrpcGreeterImpl":
- # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ "greeterImpl":
registry: "demoZk"
- protocol : "grpc"
- interface : "io.grpc.examples.helloworld.GreeterGrpc$IGreeter"
+ protocol: "grpc"
+ interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
cluster: "failover"
- methods :
+ methods:
- name: "SayHello"
retries: 3
-
+# protocol config
protocol_conf:
grpc:
reconnect_interval: 0
@@ -55,9 +50,10 @@ protocol_conf:
keep_alive_period: "120s"
tcp_r_buf_size: 262144
tcp_w_buf_size: 65536
+ pkg_rq_size: 1024
pkg_wq_size: 512
tcp_read_timeout: "1s"
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 10240
- session_name: "client"
\ No newline at end of file
+ session_name: "client"
diff --git a/general/grpc/stream/go-server/app/greeter.go b/general/grpc/stream/go-server/app/greeter.go
index d043aa9..33972c9 100644
--- a/general/grpc/stream/go-server/app/greeter.go
+++ b/general/grpc/stream/go-server/app/greeter.go
@@ -97,7 +97,3 @@ func (g *GreeterProvider) SayHelloServerStream(req *HelloRequest, server Greeter
}
return nil
}
-
-func (g *GreeterProvider) Reference() string {
- return "GrpcGreeterImpl"
-}
diff --git a/general/grpc/stream/go-server/app/helloworld.pb.go b/general/grpc/stream/go-server/app/helloworld.pb.go
index 2183a4f..4bdfb1e 100644
--- a/general/grpc/stream/go-server/app/helloworld.pb.go
+++ b/general/grpc/stream/go-server/app/helloworld.pb.go
@@ -413,6 +413,10 @@ func (s *GreeterProviderBase) GetProxyImpl() protocol.Invoker {
return s.proxyImpl
}
+func (c *GreeterProviderBase) Reference() string {
+ return "greeterImpl"
+}
+
func _DUBBO_Greeter_SayHelloTwoSidesStream_Handler(srv interface{}, stream grpc.ServerStream) error {
_, ok := srv.(dgrpc.DubboGrpcService)
invo := invocation.NewRPCInvocation("SayHelloTwoSidesStream", nil, nil)
diff --git a/general/grpc/stream/go-server/profiles/dev/server.yml b/general/grpc/stream/go-server/profiles/dev/server.yml
index 2e61183..6cf6d5d 100644
--- a/general/grpc/stream/go-server/profiles/dev/server.yml
+++ b/general/grpc/stream/go-server/profiles/dev/server.yml
@@ -1,42 +1,40 @@
# dubbo server yaml configure file
-
# application config
application:
- organization : "ikurento.com"
- name : "BDTService"
- module : "dubbogo say-hello client"
- version : "0.0.1"
- owner : "ZX"
- environment : "dev"
+ organization: "dubbo.io"
+ name: "GreeterGrpcServer"
+ module: "dubbo-go greeter grpc server"
+ version: "0.0.1"
+ environment: "dev"
-registries :
+# registry config
+registries:
"zk":
protocol: "zookeeper"
- timeout : "3s"
+ timeout: "3s"
address: "127.0.0.1:2181"
+# service config
services:
- "GrpcGreeterImpl":
- # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ "greeterImpl":
registry: "zk"
- protocol : "grpc"
- # 相当于dubbo.xml中的interface
- interface : "io.grpc.examples.helloworld.GreeterGrpc$IGreeter"
+ protocol: "grpc"
+ interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
loadbalance: "random"
warmup: "100"
cluster: "failover"
methods:
- - name: "SayHello"
- retries: 1
- loadbalance: "random"
+ - name: "SayHello"
+ retries: 1
+ loadbalance: "random"
+# protocol config
protocols:
"grpc":
name: "grpc"
port: 20000
-
protocol_conf:
grpc:
session_number: 700
@@ -54,4 +52,4 @@ protocol_conf:
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024
- session_name: "server"
+ session_name: "server"
\ No newline at end of file
diff --git a/general/grpc/stream/go-server/profiles/release/server.yml b/general/grpc/stream/go-server/profiles/release/server.yml
index 214aa14..6cf6d5d 100644
--- a/general/grpc/stream/go-server/profiles/release/server.yml
+++ b/general/grpc/stream/go-server/profiles/release/server.yml
@@ -1,25 +1,26 @@
# dubbo server yaml configure file
+
+# application config
application:
- organization : "ikurento.com"
- name : "BDTService"
- module : "dubbogo say-hello client"
- version : "0.0.1"
- owner : "ZX"
- environment : "dev"
+ organization: "dubbo.io"
+ name: "GreeterGrpcServer"
+ module: "dubbo-go greeter grpc server"
+ version: "0.0.1"
+ environment: "dev"
-registries :
- "demoZk":
+# registry config
+registries:
+ "zk":
protocol: "zookeeper"
- timeout : "3s"
+ timeout: "3s"
address: "127.0.0.1:2181"
+# service config
services:
- "GrpcGreeterImpl":
- # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
- registry: "demoZk"
- protocol : "grpc"
- # 相当于dubbo.xml中的interface
- interface : "io.grpc.examples.helloworld.GreeterGrpc$IGreeter"
+ "greeterImpl":
+ registry: "zk"
+ protocol: "grpc"
+ interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
loadbalance: "random"
warmup: "100"
cluster: "failover"
@@ -28,12 +29,12 @@ services:
retries: 1
loadbalance: "random"
+# protocol config
protocols:
"grpc":
name: "grpc"
port: 20000
-
protocol_conf:
grpc:
session_number: 700
@@ -51,4 +52,4 @@ protocol_conf:
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024
- session_name: "server"
+ session_name: "server"
\ No newline at end of file
diff --git a/general/grpc/stream/go-server/profiles/test/server.yml b/general/grpc/stream/go-server/profiles/test/server.yml
index 14e9ecb..6cf6d5d 100644
--- a/general/grpc/stream/go-server/profiles/test/server.yml
+++ b/general/grpc/stream/go-server/profiles/test/server.yml
@@ -10,15 +10,15 @@ application:
# registry config
registries:
- "demoZk":
+ "zk":
protocol: "zookeeper"
timeout: "3s"
address: "127.0.0.1:2181"
# service config
services:
- "GrpcGreeterImpl":
- registry: "demoZk"
+ "greeterImpl":
+ registry: "zk"
protocol: "grpc"
interface: "org.apache.dubbo.GreeterGrpc$IGreeter"
loadbalance: "random"
@@ -52,4 +52,4 @@ protocol_conf:
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024
- session_name: "server"
+ session_name: "server"
\ No newline at end of file
diff --git a/general/grpc/unary/go-client/app/client.go b/general/grpc/unary/go-client/app/client.go
index f39b32f..6dd2cc7 100644
--- a/general/grpc/unary/go-client/app/client.go
+++ b/general/grpc/unary/go-client/app/client.go
@@ -34,11 +34,7 @@ import (
gxlog "github.com/dubbogo/gost/log"
)
-import (
- "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
-)
-
-var grpcGreeterImpl = new(GrpcGreeterImpl)
+var grpcGreeterImpl = new(GreeterClientImpl)
func init() {
config.SetConsumerService(grpcGreeterImpl)
@@ -50,8 +46,8 @@ func main() {
time.Sleep(3 * time.Second)
gxlog.CInfo("\n\n\nstart to test dubbo")
- reply := &protobuf.HelloReply{}
- req := &protobuf.HelloRequest{
+ reply := &HelloReply{}
+ req := &HelloRequest{
Name: "xujianhai",
}
err := grpcGreeterImpl.SayHello(context.TODO(), req, reply)
diff --git a/general/grpc/unary/go-client/app/hello.go b/general/grpc/unary/go-client/app/hello.go
deleted file mode 100644
index 95b78c5..0000000
--- a/general/grpc/unary/go-client/app/hello.go
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 (
- "context"
-)
-
-import (
- "google.golang.org/grpc"
-)
-
-import (
- "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
-)
-
-type GrpcGreeterImpl struct {
- SayHello func(ctx context.Context, in *protobuf.HelloRequest, out *protobuf.HelloReply) error
-}
-
-func (u *GrpcGreeterImpl) Reference() string {
- return "GrpcGreeterImpl"
-}
-
-func (u *GrpcGreeterImpl) GetDubboStub(cc *grpc.ClientConn) protobuf.GreeterClient {
- return protobuf.NewGreeterClient(cc)
-}
diff --git a/general/grpc/unary/go-client/app/helloworld.pb.go b/general/grpc/unary/go-client/app/helloworld.pb.go
index 75e18b9..e0e9b31 100644
--- a/general/grpc/unary/go-client/app/helloworld.pb.go
+++ b/general/grpc/unary/go-client/app/helloworld.pb.go
@@ -4,14 +4,13 @@
package main
import (
- "context"
- "fmt"
- "math"
-
- "github.com/golang/protobuf/proto"
- "google.golang.org/grpc"
- "google.golang.org/grpc/codes"
- "google.golang.org/grpc/status"
+ context "context"
+ fmt "fmt"
+ proto "github.com/golang/protobuf/proto"
+ grpc "google.golang.org/grpc"
+ codes "google.golang.org/grpc/codes"
+ status "google.golang.org/grpc/status"
+ math "math"
)
import (
@@ -244,6 +243,10 @@ func (s *GreeterProviderBase) GetProxyImpl() protocol.Invoker {
return s.proxyImpl
}
+func (c *GreeterProviderBase) Reference() string {
+ return "greeterImpl"
+}
+
func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HelloRequest)
if err := dec(in); err != nil {
@@ -254,7 +257,7 @@ func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec f
args = append(args, in)
invo := invocation.NewRPCInvocation("SayHello", args, nil)
if interceptor == nil {
- result := base.GetProxyImpl().Invoke(context.Background(), invo)
+ result := base.GetProxyImpl().Invoke(ctx, invo)
return result.Result(), result.Error()
}
info := &grpc.UnaryServerInfo{
@@ -262,7 +265,7 @@ func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec f
FullMethod: "/main.Greeter/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
- result := base.GetProxyImpl().Invoke(context.Background(), invo)
+ result := base.GetProxyImpl().Invoke(ctx, invo)
return result.Result(), result.Error()
}
return interceptor(ctx, in, info, handler)
diff --git a/general/grpc/unary/go-client/app/helloworld.proto b/general/grpc/unary/go-client/app/helloworld.proto
index 3a440cd..d68e1dd 100644
--- a/general/grpc/unary/go-client/app/helloworld.proto
+++ b/general/grpc/unary/go-client/app/helloworld.proto
@@ -14,11 +14,11 @@
syntax = "proto3";
option java_multiple_files = true;
-option java_package = "org.apache.dubbo";
+option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
-package protobuf;
+package main;
// The greeting service definition.
service Greeter {
diff --git a/general/grpc/unary/go-client/profiles/dev/client.yml b/general/grpc/unary/go-client/profiles/dev/client.yml
index d04a578..0fc1bb9 100644
--- a/general/grpc/unary/go-client/profiles/dev/client.yml
+++ b/general/grpc/unary/go-client/profiles/dev/client.yml
@@ -26,7 +26,7 @@ registries :
references:
- "GrpcGreeterImpl":
+ "greeterImpl":
# 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
registry: "demoZk"
protocol : "grpc"
diff --git a/general/grpc/unary/go-client/profiles/release/client.yml b/general/grpc/unary/go-client/profiles/release/client.yml
index 265654c..bc1bae2 100644
--- a/general/grpc/unary/go-client/profiles/release/client.yml
+++ b/general/grpc/unary/go-client/profiles/release/client.yml
@@ -26,7 +26,7 @@ registries :
references:
- "GrpcGreeterImpl":
+ "greeterImpl":
# 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
registry: "demoZk"
protocol : "grpc"
diff --git a/general/grpc/unary/go-client/profiles/test/client.yml b/general/grpc/unary/go-client/profiles/test/client.yml
index e0c0737..48d158b 100644
--- a/general/grpc/unary/go-client/profiles/test/client.yml
+++ b/general/grpc/unary/go-client/profiles/test/client.yml
@@ -29,7 +29,7 @@ registries :
password: ""
references:
- "GrpcGreeterImpl":
+ "greeterImpl":
# 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
registry: "demoZk"
protocol : "grpc"
diff --git a/general/grpc/unary/go-server/app/greeter.go b/general/grpc/unary/go-server/app/greeter.go
index a659a28..e5471f3 100644
--- a/general/grpc/unary/go-server/app/greeter.go
+++ b/general/grpc/unary/go-server/app/greeter.go
@@ -22,25 +22,18 @@ import (
"fmt"
)
-import (
- "github.com/apache/dubbo-go-samples/general/grpc/protobuf"
-)
type GreeterProvider struct {
- *protobuf.GreeterProviderBase
+ *GreeterProviderBase
}
func NewGreeterProvider() *GreeterProvider {
return &GreeterProvider{
- GreeterProviderBase: &protobuf.GreeterProviderBase{},
+ GreeterProviderBase: &GreeterProviderBase{},
}
}
-func (g *GreeterProvider) SayHello(ctx context.Context, req *protobuf.HelloRequest) (reply *protobuf.HelloReply, err error) {
+func (g *GreeterProvider) SayHello(ctx context.Context, req *HelloRequest) (reply *HelloReply, err error) {
fmt.Printf("req: %v", req)
- return &protobuf.HelloReply{Message: "this is message from reply"}, nil
-}
-
-func (g *GreeterProvider) Reference() string {
- return "GrpcGreeterImpl"
+ return &HelloReply{Message: "this is message from reply"}, nil
}
diff --git a/general/grpc/unary/go-server/app/helloworld.pb.go b/general/grpc/unary/go-server/app/helloworld.pb.go
index 3f17426..e0e9b31 100644
--- a/general/grpc/unary/go-server/app/helloworld.pb.go
+++ b/general/grpc/unary/go-server/app/helloworld.pb.go
@@ -111,35 +111,35 @@ func (m *HelloReply) GetMessage() string {
}
func init() {
- proto.RegisterType((*HelloRequest)(nil), "protobuf.HelloRequest")
- proto.RegisterType((*HelloReply)(nil), "protobuf.HelloReply")
+ proto.RegisterType((*HelloRequest)(nil), "main.HelloRequest")
+ proto.RegisterType((*HelloReply)(nil), "main.HelloReply")
}
func init() { proto.RegisterFile("helloworld.proto", fileDescriptor_17b8c58d586b62f2) }
var fileDescriptor_17b8c58d586b62f2 = []byte{
- // 183 bytes of a gzipped FileDescriptorProto
+ // 185 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc8, 0x48, 0xcd, 0xc9,
- 0xc9, 0x2f, 0xcf, 0x2f, 0xca, 0x49, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x00, 0x53,
- 0x49, 0xa5, 0x69, 0x4a, 0x4a, 0x5c, 0x3c, 0x1e, 0x20, 0xd9, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2,
- 0x12, 0x21, 0x21, 0x2e, 0x96, 0xbc, 0xc4, 0xdc, 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20,
- 0x30, 0x5b, 0x49, 0x8d, 0x8b, 0x0b, 0xaa, 0xa6, 0x20, 0xa7, 0x52, 0x48, 0x82, 0x8b, 0x3d, 0x37,
- 0xb5, 0xb8, 0x38, 0x31, 0x1d, 0xa6, 0x08, 0xc6, 0x35, 0x72, 0xe5, 0x62, 0x77, 0x2f, 0x4a, 0x4d,
- 0x2d, 0x49, 0x2d, 0x12, 0xb2, 0xe2, 0xe2, 0x08, 0x4e, 0xac, 0x04, 0xeb, 0x12, 0x12, 0xd3, 0x83,
- 0xd9, 0xa6, 0x87, 0x6c, 0x95, 0x94, 0x08, 0x86, 0x78, 0x41, 0x4e, 0xa5, 0x12, 0x83, 0x93, 0x36,
- 0x97, 0x40, 0x7e, 0x51, 0xba, 0x5e, 0x62, 0x41, 0x62, 0x72, 0x46, 0xaa, 0x5e, 0x4a, 0x69, 0x52,
- 0x52, 0xbe, 0x13, 0x3f, 0x58, 0x45, 0x38, 0xc8, 0x0b, 0x01, 0x20, 0x4d, 0x01, 0x8c, 0x8b, 0x98,
- 0x98, 0x3d, 0x7c, 0xc2, 0x93, 0xd8, 0xc0, 0x66, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xde,
- 0x1e, 0xf0, 0xa3, 0xe4, 0x00, 0x00, 0x00,
+ 0xc9, 0x2f, 0xcf, 0x2f, 0xca, 0x49, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d,
+ 0xcc, 0xcc, 0x53, 0x52, 0xe2, 0xe2, 0xf1, 0x00, 0xc9, 0x04, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97,
+ 0x08, 0x09, 0x71, 0xb1, 0xe4, 0x25, 0xe6, 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81,
+ 0xd9, 0x4a, 0x6a, 0x5c, 0x5c, 0x50, 0x35, 0x05, 0x39, 0x95, 0x42, 0x12, 0x5c, 0xec, 0xb9, 0xa9,
+ 0xc5, 0xc5, 0x89, 0xe9, 0x30, 0x45, 0x30, 0xae, 0x91, 0x2d, 0x17, 0xbb, 0x7b, 0x51, 0x6a, 0x6a,
+ 0x49, 0x6a, 0x91, 0x90, 0x11, 0x17, 0x47, 0x70, 0x62, 0x25, 0x58, 0x97, 0x90, 0x90, 0x1e, 0xc8,
+ 0x26, 0x3d, 0x64, 0x6b, 0xa4, 0x04, 0x50, 0xc4, 0x0a, 0x72, 0x2a, 0x95, 0x18, 0x9c, 0xcc, 0xb8,
+ 0xa4, 0x33, 0xf3, 0xf5, 0xd2, 0x8b, 0x0a, 0x92, 0xf5, 0x52, 0x2b, 0x12, 0x73, 0x0b, 0x72, 0x52,
+ 0x8b, 0xf5, 0x10, 0xae, 0x76, 0xe2, 0x07, 0x2b, 0x0e, 0x07, 0xb1, 0x03, 0x40, 0x1e, 0x08, 0x60,
+ 0x5c, 0xc4, 0xc4, 0xec, 0xe1, 0x13, 0x9e, 0xc4, 0x06, 0xf6, 0x8f, 0x31, 0x20, 0x00, 0x00, 0xff,
+ 0xff, 0xd2, 0x16, 0x5f, 0x34, 0xe3, 0x00, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
-var _ grpc.ClientConnInterface
+var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
-const _ = grpc.SupportPackageIsVersion6
+const _ = grpc.SupportPackageIsVersion4
// GreeterClient is the client API for Greeter service.
//
@@ -150,16 +150,16 @@ type GreeterClient interface {
}
type greeterClient struct {
- cc grpc.ClientConnInterface
+ cc *grpc.ClientConn
}
-func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient {
+func NewGreeterClient(cc *grpc.ClientConn) GreeterClient {
return &greeterClient{cc}
}
func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) {
out := new(HelloReply)
- err := c.cc.Invoke(ctx, "/protobuf.Greeter/SayHello", in, out, opts...)
+ err := c.cc.Invoke(ctx, "/main.Greeter/SayHello", in, out, opts...)
if err != nil {
return nil, err
}
@@ -194,7 +194,7 @@ func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(in
}
info := &grpc.UnaryServerInfo{
Server: srv,
- FullMethod: "/protobuf.Greeter/SayHello",
+ FullMethod: "/main.Greeter/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest))
@@ -203,7 +203,7 @@ func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(in
}
var _Greeter_serviceDesc = grpc.ServiceDesc{
- ServiceName: "protobuf.Greeter",
+ ServiceName: "main.Greeter",
HandlerType: (*GreeterServer)(nil),
Methods: []grpc.MethodDesc{
{
@@ -243,6 +243,10 @@ func (s *GreeterProviderBase) GetProxyImpl() protocol.Invoker {
return s.proxyImpl
}
+func (c *GreeterProviderBase) Reference() string {
+ return "greeterImpl"
+}
+
func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HelloRequest)
if err := dec(in); err != nil {
@@ -253,15 +257,15 @@ func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec f
args = append(args, in)
invo := invocation.NewRPCInvocation("SayHello", args, nil)
if interceptor == nil {
- result := base.GetProxyImpl().Invoke(context.Background(), invo)
+ result := base.GetProxyImpl().Invoke(ctx, invo)
return result.Result(), result.Error()
}
info := &grpc.UnaryServerInfo{
Server: srv,
- FullMethod: "/protobuf.Greeter/SayHello",
+ FullMethod: "/main.Greeter/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
- result := base.GetProxyImpl().Invoke(context.Background(), invo)
+ result := base.GetProxyImpl().Invoke(ctx, invo)
return result.Result(), result.Error()
}
return interceptor(ctx, in, info, handler)
@@ -269,7 +273,7 @@ func _DUBBO_Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec f
func (s *GreeterProviderBase) ServiceDesc() *grpc.ServiceDesc {
return &grpc.ServiceDesc{
- ServiceName: "protobuf.Greeter",
+ ServiceName: "main.Greeter",
HandlerType: (*GreeterServer)(nil),
Methods: []grpc.MethodDesc{
{
diff --git a/general/grpc/unary/go-server/profiles/dev/server.yml b/general/grpc/unary/go-server/profiles/dev/server.yml
index 2e61183..df37534 100644
--- a/general/grpc/unary/go-server/profiles/dev/server.yml
+++ b/general/grpc/unary/go-server/profiles/dev/server.yml
@@ -17,7 +17,7 @@ registries :
address: "127.0.0.1:2181"
services:
- "GrpcGreeterImpl":
+ "greeterImpl":
# 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
registry: "zk"
protocol : "grpc"
diff --git a/general/grpc/unary/go-server/profiles/release/server.yml b/general/grpc/unary/go-server/profiles/release/server.yml
index 214aa14..8c9b2db 100644
--- a/general/grpc/unary/go-server/profiles/release/server.yml
+++ b/general/grpc/unary/go-server/profiles/release/server.yml
@@ -14,7 +14,7 @@ registries :
address: "127.0.0.1:2181"
services:
- "GrpcGreeterImpl":
+ "greeterImpl":
# 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
registry: "demoZk"
protocol : "grpc"
diff --git a/general/grpc/unary/go-server/profiles/test/server.yml b/general/grpc/unary/go-server/profiles/test/server.yml
index da146ad..49674e3 100644
--- a/general/grpc/unary/go-server/profiles/test/server.yml
+++ b/general/grpc/unary/go-server/profiles/test/server.yml
@@ -17,7 +17,7 @@ registries :
address: "127.0.0.1:2181"
services:
- "GrpcGreeterImpl":
+ "greeterImpl":
# 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
registry: "demoZk"
protocol : "grpc"
diff --git a/go.sum b/go.sum
index 96d650d..a92f848 100644
--- a/go.sum
+++ b/go.sum
@@ -1050,6 +1050,7 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=