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/22 10:13:07 UTC

[dubbo-go-samples] branch config-enhance updated: Ftr: registry/etcd sample using dubbogo.yml (#252)

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 ae69f43  Ftr: registry/etcd sample using dubbogo.yml (#252)
ae69f43 is described below

commit ae69f43256a1c7ed3dd6291cf5199d0ceabedad4
Author: phil <ph...@foxmail.com>
AuthorDate: Wed Sep 22 18:12:59 2021 +0800

    Ftr: registry/etcd sample using dubbogo.yml (#252)
    
    * refactor: registry/etcd sample using dubbogo.yml
    
    * refactor: ETCD Sample use the new config `dubbogo.yml`
    
    * fix: add .run config of JSON-RPC sample
    
    Co-authored-by: yuefengbo <yu...@meituan.com>
---
 .run/registry/etcd/registry_etcd_go-client.run.xml | 14 +++++
 .run/registry/etcd/registry_etcd_go-server.run.xml | 14 +++++
 .run/rpc/jsonrpc/rpc-jsonrpc-go-server.run.xml     | 14 +++++
 .../registry/etcd}/tests/integration/main_test.go  | 39 ++++----------
 .../etcd}/tests/integration/userprovider_test.go   |  8 ++-
 registry/etcd/go-client/cmd/client.go              | 22 ++++----
 registry/etcd/go-client/conf/client.yml            | 59 ----------------------
 registry/etcd/go-client/conf/dubbogo.yml           | 22 ++++++++
 registry/etcd/go-client/pkg/user.go                |  6 +--
 registry/etcd/go-server/cmd/server.go              | 12 ++---
 registry/etcd/go-server/conf/client.yml            | 59 ----------------------
 registry/etcd/go-server/conf/dubbogo.yml           | 23 +++++++++
 registry/etcd/go-server/conf/server.yml            | 55 --------------------
 registry/etcd/go-server/pkg/user.go                |  8 +--
 start_integrate_test.sh                            |  1 +
 15 files changed, 120 insertions(+), 236 deletions(-)

diff --git a/.run/registry/etcd/registry_etcd_go-client.run.xml b/.run/registry/etcd/registry_etcd_go-client.run.xml
new file mode 100644
index 0000000..8f897fd
--- /dev/null
+++ b/.run/registry/etcd/registry_etcd_go-client.run.xml
@@ -0,0 +1,14 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="registry/etcd/go-client" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="registry">
+    <module name="dubbo-go-samples" />
+    <working_directory value="$PROJECT_DIR$" />
+    <envs>
+      <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/registry/etcd/go-client/conf/dubbogo.yml" />
+    </envs>
+    <kind value="PACKAGE" />
+    <package value="github.com/apache/dubbo-go-samples/registry/etcd/go-client/cmd" />
+    <directory value="$PROJECT_DIR$" />
+    <filePath value="$PROJECT_DIR$/registry/etcd/go-client/cmd/client.go" />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/.run/registry/etcd/registry_etcd_go-server.run.xml b/.run/registry/etcd/registry_etcd_go-server.run.xml
new file mode 100644
index 0000000..09eeaf5
--- /dev/null
+++ b/.run/registry/etcd/registry_etcd_go-server.run.xml
@@ -0,0 +1,14 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="registry/etcd/go-server" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="registry">
+    <module name="dubbo-go-samples" />
+    <working_directory value="$PROJECT_DIR$" />
+    <envs>
+      <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/registry/etcd/go-server/conf/dubbogo.yml" />
+    </envs>
+    <kind value="PACKAGE" />
+    <package value="github.com/apache/dubbo-go-samples/registry/etcd/go-server/cmd" />
+    <directory value="$PROJECT_DIR$" />
+    <filePath value="$PROJECT_DIR$/registry/etcd/go-server/cmd/server.go" />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/.run/rpc/jsonrpc/rpc-jsonrpc-go-server.run.xml b/.run/rpc/jsonrpc/rpc-jsonrpc-go-server.run.xml
new file mode 100644
index 0000000..544f751
--- /dev/null
+++ b/.run/rpc/jsonrpc/rpc-jsonrpc-go-server.run.xml
@@ -0,0 +1,14 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="rpc-jsonrpc-go-server" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="rpc/jsonrpc">
+    <module name="dubbo-go-samples" />
+    <working_directory value="$PROJECT_DIR$" />
+    <envs>
+      <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/rpc/jsonrpc/go-server/conf/dubbogo.yml" />
+    </envs>
+    <kind value="PACKAGE" />
+    <package value="github.com/apache/dubbo-go-samples/rpc/jsonrpc/go-server/cmd" />
+    <directory value="$PROJECT_DIR$" />
+    <filePath value="$PROJECT_DIR$/rpc/jsonrpc/go-server/cmd/server.go" />
+    <method v="2" />
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/registry/etcd/go-server/tests/integration/main_test.go b/integrate_test/registry/etcd/tests/integration/main_test.go
similarity index 59%
rename from registry/etcd/go-server/tests/integration/main_test.go
rename to integrate_test/registry/etcd/tests/integration/main_test.go
index b9a70f6..0fe7ad2 100644
--- a/registry/etcd/go-server/tests/integration/main_test.go
+++ b/integrate_test/registry/etcd/tests/integration/main_test.go
@@ -20,51 +20,32 @@
 package integration
 
 import (
-	"context"
 	"os"
 	"testing"
 	"time"
 )
 
 import (
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
-	_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
+	_ "dubbo.apache.org/dubbo-go/v3/common/logger"
 	"dubbo.apache.org/dubbo-go/v3/config"
-	_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/etcdv3"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
+	_ "dubbo.apache.org/dubbo-go/v3/imports"
 
 	hessian "github.com/apache/dubbo-go-hessian2"
 )
 
-var userProvider = new(UserProvider)
+import (
+	"github.com/apache/dubbo-go-samples/registry/etcd/go-client/pkg"
+)
+
+var (
+	userProvider = &pkg.UserProvider{}
+)
 
 func TestMain(m *testing.M) {
 	config.SetConsumerService(userProvider)
-	hessian.RegisterPOJO(&User{})
+	hessian.RegisterPOJO(&pkg.User{})
 	config.Load()
 	time.Sleep(3 * time.Second)
 
 	os.Exit(m.Run())
 }
-
-type User struct {
-	ID   string
-	Name string
-	Age  int32
-	Time time.Time
-}
-
-type UserProvider struct {
-	GetUser func(ctx context.Context, req []interface{}, rsp *User) error
-}
-
-func (u *UserProvider) Reference() string {
-	return "UserProvider"
-}
-
-func (User) JavaClassName() string {
-	return "org.apache.dubbo.User"
-}
diff --git a/registry/etcd/go-server/tests/integration/userprovider_test.go b/integrate_test/registry/etcd/tests/integration/userprovider_test.go
similarity index 87%
rename from registry/etcd/go-server/tests/integration/userprovider_test.go
rename to integrate_test/registry/etcd/tests/integration/userprovider_test.go
index 7183e64..3a18da3 100644
--- a/registry/etcd/go-server/tests/integration/userprovider_test.go
+++ b/integrate_test/registry/etcd/tests/integration/userprovider_test.go
@@ -28,9 +28,13 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
+import (
+	"github.com/apache/dubbo-go-samples/registry/etcd/go-client/pkg"
+)
+
 func TestGetUser(t *testing.T) {
-	user := &User{}
-	err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+	user := &pkg.User{ID: "A001"}
+	user, err := userProvider.GetUser(context.TODO(), user)
 	assert.Nil(t, err)
 	assert.Equal(t, "A001", user.ID)
 	assert.Equal(t, "Alex Stocks", user.Name)
diff --git a/registry/etcd/go-client/cmd/client.go b/registry/etcd/go-client/cmd/client.go
index 786422b..31b05fb 100644
--- a/registry/etcd/go-client/cmd/client.go
+++ b/registry/etcd/go-client/cmd/client.go
@@ -24,18 +24,10 @@ import (
 )
 
 import (
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
-	_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
 	"dubbo.apache.org/dubbo-go/v3/config"
-	_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/etcdv3"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
-
+	_ "dubbo.apache.org/dubbo-go/v3/imports"
 	hessian "github.com/apache/dubbo-go-hessian2"
-
-	"github.com/dubbogo/gost/log"
+	gxlog "github.com/dubbogo/gost/log"
 )
 
 import (
@@ -49,15 +41,19 @@ func init() {
 	hessian.RegisterPOJO(&pkg.User{})
 }
 
-// need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run
+// Do some checking before the system starts up:
+// 1. env config
+// 		`export DUBBO_GO_CONFIG_PATH= ROOT_PATH/conf/dubbogo.yml` or `dubbogo.yaml`
 func main() {
 	hessian.RegisterPOJO(&pkg.User{})
 	config.Load()
 	time.Sleep(3 * time.Second)
 
 	gxlog.CInfo("\n\n\nstart to test dubbo")
-	user := &pkg.User{}
-	err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+	user := &pkg.User{
+		ID: "A001",
+	}
+	user, err := userProvider.GetUser(context.TODO(), user)
 	if err != nil {
 		gxlog.CError("error: %v\n", err)
 		os.Exit(1)
diff --git a/registry/etcd/go-client/conf/client.yml b/registry/etcd/go-client/conf/client.yml
deleted file mode 100644
index e514c2e..0000000
--- a/registry/etcd/go-client/conf/client.yml
+++ /dev/null
@@ -1,59 +0,0 @@
-# dubbo client yaml configure file
-
-check: true
-# client
-request_timeout: "3s"
-# connect timeout
-connect_timeout: "3s"
-
-# application config
-application:
-  organization: "dubbo.io"
-  name: "UserInfoClient"
-  module: "dubbo-go user-info client"
-  version: "0.0.1"
-  environment: "dev"
-
-# registry config
-registries:
-  "etcd":
-    protocol: "etcdv3"
-    timeout: "3s"
-    address: "127.0.0.1:2379"
-    username: ""
-    password: ""
-
-# reference config
-references:
-  "UserProvider":
-    registry: "etcd"
-    protocol: "dubbo"
-    interface: "org.apache.dubbo.UserProvider"
-    cluster: "failover"
-    methods:
-      - name: "GetUser"
-        retries: 3
-
-# protocol config
-protocol_conf:
-  dubbo:
-    reconnect_interval: 0
-    connection_number: 1
-    heartbeat_period: "5s"
-    session_timeout: "180s"
-    pool_size: 64
-    pool_ttl: 600
-    getty_session_param:
-      compress_encoding: false
-      tcp_no_delay: true
-      tcp_keep_alive: true
-      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: 1024000
-      session_name: "client"
diff --git a/registry/etcd/go-client/conf/dubbogo.yml b/registry/etcd/go-client/conf/dubbogo.yml
new file mode 100644
index 0000000..52c8b74
--- /dev/null
+++ b/registry/etcd/go-client/conf/dubbogo.yml
@@ -0,0 +1,22 @@
+dubbo:
+  application:
+    organization: "dubbo.io"
+    name: "UserInfoClient"
+    module: "dubbo-go user-info client"
+    version: "0.0.1"
+    environment: "dev"
+  registries:
+    etcd:
+      protocol: "etcdv3"
+      timeout: "3s"
+      address: "127.0.0.1:2379"
+  protocols:
+    dubbo:
+      name: "dubbo"
+      port: 20000
+  consumer:
+    references:
+      UserProvider:
+        registry: "etcd"
+        protocol: "dubbo"
+        interface: "org.apache.dubbo.UserProvider"
\ No newline at end of file
diff --git a/registry/etcd/go-client/pkg/user.go b/registry/etcd/go-client/pkg/user.go
index 7733ea4..4b06253 100644
--- a/registry/etcd/go-client/pkg/user.go
+++ b/registry/etcd/go-client/pkg/user.go
@@ -30,11 +30,7 @@ type User struct {
 }
 
 type UserProvider struct {
-	GetUser func(ctx context.Context, req []interface{}, rsp *User) error
-}
-
-func (u *UserProvider) Reference() string {
-	return "UserProvider"
+	GetUser func(ctx context.Context, user *User) (*User, error)
 }
 
 func (User) JavaClassName() string {
diff --git a/registry/etcd/go-server/cmd/server.go b/registry/etcd/go-server/cmd/server.go
index 2b4b7f4..adea6ba 100644
--- a/registry/etcd/go-server/cmd/server.go
+++ b/registry/etcd/go-server/cmd/server.go
@@ -26,15 +26,9 @@ import (
 )
 
 import (
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
 	"dubbo.apache.org/dubbo-go/v3/common/logger"
-	_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
 	"dubbo.apache.org/dubbo-go/v3/config"
-	_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/etcdv3"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
+	_ "dubbo.apache.org/dubbo-go/v3/imports"
 
 	hessian "github.com/apache/dubbo-go-hessian2"
 )
@@ -47,7 +41,9 @@ var (
 	survivalTimeout = int(3e9)
 )
 
-// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run
+// Do some checking before the system starts up:
+// 1. env config
+// 		`export DUBBO_GO_CONFIG_PATH= ROOT_PATH/conf/dubbogo.yml` or `dubbogo.yaml`
 func main() {
 	hessian.RegisterPOJO(&pkg.User{})
 	config.Load()
diff --git a/registry/etcd/go-server/conf/client.yml b/registry/etcd/go-server/conf/client.yml
deleted file mode 100644
index 0832a89..0000000
--- a/registry/etcd/go-server/conf/client.yml
+++ /dev/null
@@ -1,59 +0,0 @@
-# dubbo client yaml configure file
-
-check: true
-# client
-request_timeout: "3s"
-# connect timeout
-connect_timeout: "3s"
-
-# application config
-application:
-  organization: "dubbo.io"
-  name: "UserInfoTest"
-  module: "dubbo-go user-info client"
-  version: "0.0.1"
-  environment: "dev"
-
-# registry config
-registries:
-  "etcd":
-    protocol: "etcdv3"
-    timeout: "3s"
-    address: "127.0.0.1:2379"
-    username: ""
-    password: ""
-
-# reference config
-references:
-  "UserProvider":
-    registry: "etcd"
-    protocol: "dubbo"
-    interface: "org.apache.dubbo.UserProvider"
-    cluster: "failover"
-    methods:
-      - name: "GetUser"
-        retries: 3
-
-# protocol config
-protocol_conf:
-  dubbo:
-    reconnect_interval: 0
-    connection_number: 1
-    heartbeat_period: "5s"
-    session_timeout: "180s"
-    pool_size: 64
-    pool_ttl: 600
-    getty_session_param:
-      compress_encoding: false
-      tcp_no_delay: true
-      tcp_keep_alive: true
-      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: 1024000
-      session_name: "client"
diff --git a/registry/etcd/go-server/conf/dubbogo.yml b/registry/etcd/go-server/conf/dubbogo.yml
new file mode 100644
index 0000000..844bbd0
--- /dev/null
+++ b/registry/etcd/go-server/conf/dubbogo.yml
@@ -0,0 +1,23 @@
+dubbo:
+  application:
+    organization: "dubbo.io"
+    name: "UserInfoServer"
+    module: "dubbo-go user-info server"
+    version: "0.0.1"
+    environment: "dev"
+  registries:
+    etcd:
+      protocol: "etcdv3"
+      timeout: "3s"
+      address: "127.0.0.1:2379"
+  protocols:
+    dubbo:
+      name: "dubbo"
+      port: 20000
+  provider:
+    registry:
+      - etcd
+    services:
+      UserProvider:
+        protocol: "dubbo"
+        interface: "org.apache.dubbo.UserProvider"
\ No newline at end of file
diff --git a/registry/etcd/go-server/conf/server.yml b/registry/etcd/go-server/conf/server.yml
deleted file mode 100644
index 3099fd2..0000000
--- a/registry/etcd/go-server/conf/server.yml
+++ /dev/null
@@ -1,55 +0,0 @@
-# dubbo server yaml configure file
-
-# application config
-application:
-  organization: "dubbo.io"
-  name: "UserInfoServer"
-  module: "dubbo-go user-info server"
-  version: "0.0.1"
-  environment: "dev"
-
-# registry config
-registries:
-  "etcd":
-    protocol: "etcdv3"
-    timeout: "3s"
-    address: "127.0.0.1:2379"
-
-# service config
-services:
-  "UserProvider":
-    registry: "etcd"
-    protocol: "dubbo"
-    interface: "org.apache.dubbo.UserProvider"
-    loadbalance: "random"
-    warmup: "100"
-    cluster: "failover"
-    methods:
-      - name: "GetUser"
-        retries: 1
-        loadbalance: "random"
-
-# protocol config
-protocols:
-  "dubbo":
-    name: "dubbo"
-    port: 20000
-
-protocol_conf:
-  dubbo:
-    session_number: 700
-    session_timeout: "180s"
-    getty_session_param:
-      compress_encoding: false
-      tcp_no_delay: true
-      tcp_keep_alive: true
-      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: 1024000
-      session_name: "server"
diff --git a/registry/etcd/go-server/pkg/user.go b/registry/etcd/go-server/pkg/user.go
index 75d0916..ec55bcf 100644
--- a/registry/etcd/go-server/pkg/user.go
+++ b/registry/etcd/go-server/pkg/user.go
@@ -31,7 +31,7 @@ import (
 )
 
 func init() {
-	config.SetProviderService(new(UserProvider))
+	config.SetProviderService(&UserProvider{})
 	// ------for hessian2------
 	hessian.RegisterPOJO(&User{})
 }
@@ -46,17 +46,13 @@ type User struct {
 type UserProvider struct {
 }
 
-func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) {
+func (u *UserProvider) GetUser(ctx context.Context, req *User) (*User, error) {
 	gxlog.CInfo("req:%#v", req)
 	rsp := User{"A001", "Alex Stocks", 18, time.Now()}
 	gxlog.CInfo("rsp:%#v", rsp)
 	return &rsp, nil
 }
 
-func (u *UserProvider) Reference() string {
-	return "UserProvider"
-}
-
 func (u User) JavaClassName() string {
 	return "org.apache.dubbo.User"
 }
diff --git a/start_integrate_test.sh b/start_integrate_test.sh
index 8a287ab..80e3555 100755
--- a/start_integrate_test.sh
+++ b/start_integrate_test.sh
@@ -101,6 +101,7 @@ array+=("config-api/configcenter/zookeeper")
 # registry
 array+=("registry/zookeeper")
 array+=("registry/nacos")
+array+=("registry/etcd")
 
 # generic
 array+=("generic/default")