This is an automated email from the ASF dual-hosted git repository. zhaoyunxing pushed a commit to branch config-enhance in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
commit a2409c2c1d67e3375d0125668a9b6b42386eee8b Author: Baster <[email protected]> AuthorDate: Sat Aug 28 09:07:12 2021 +0800 Add apollo config center sample (#208) * add apollo config center sample * add apollo config center example * update config * delete debug file * add initSignal func for apollo sample * update apollo run xml * update apollo sample reademe md * add apollo test interation * update go mod Co-authored-by: zengfanwei <[email protected]> --- .../configcenter-apollo-client.run.xml | 27 +++++---- .../configcenter-apollo-server.run.xml | 27 +++++---- .run/configcenter/configcenter-apollo-test.run.xml | 9 ++- .run/helloworld-go-server.run.xml | 14 ----- configcenter/apollo/README.md | 64 +++++++++++++++++++++ configcenter/apollo/README_zh.md | 60 ++++++++++++++++++++ configcenter/apollo/go-client/cmd/client.go | 41 +++++--------- configcenter/apollo/go-client/conf/client.yml | 66 ---------------------- configcenter/apollo/go-client/conf/dubbogo.yml | 7 +++ configcenter/apollo/go-client/conf/log.yml | 28 --------- configcenter/apollo/go-client/pkg/user.go | 42 -------------- configcenter/apollo/go-server/cmd/server.go | 33 ++++++----- configcenter/apollo/go-server/conf/client.yml | 66 ---------------------- configcenter/apollo/go-server/conf/dubbogo.yml | 7 +++ configcenter/apollo/go-server/conf/log.yml | 28 --------- configcenter/apollo/go-server/conf/server.yml | 62 -------------------- configcenter/apollo/go-server/pkg/user.go | 62 -------------------- go.mod | 4 +- .../configcenter/apollo}/docker/docker-compose.yml | 0 .../apollo}/docker/docker-health-check.sh | 0 .../apollo}/docker/sql/apolloconfigdb.sql | 0 .../apollo}/docker/sql/apolloportaldb.sql | 0 .../tests/integration/greeterProvider_test.go | 26 ++++++--- .../apollo}/tests/integration/main_test.go | 30 ++-------- .../tests/integration/userprovider_test.go | 33 +++++------ 25 files changed, 242 insertions(+), 494 deletions(-) diff --git a/.run/configcenter/configcenter-apollo-client.run.xml b/.run/configcenter/configcenter-apollo-client.run.xml index 769b395..f6fdc16 100644 --- a/.run/configcenter/configcenter-apollo-client.run.xml +++ b/.run/configcenter/configcenter-apollo-client.run.xml @@ -1,15 +1,14 @@ <component name="ProjectRunConfigurationManager"> - <configuration default="false" name="configcenter-apollo-client" type="GoApplicationRunConfiguration" factoryName="Go Application" singleton="false"> - <module name="dubbo-go-samples" /> - <working_directory value="$PROJECT_DIR$" /> - <envs> - <env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/configcenter/apollo/go-client/conf/log.yml" /> - <env name="CONF_CONSUMER_FILE_PATH" value="$PROJECT_DIR$/configcenter/apollo/go-client/conf/client.yml" /> - </envs> - <kind value="PACKAGE" /> - <filePath value="$PROJECT_DIR$/configcenter/apollo/go-client/cmd/client.go" /> - <package value="github.com/apache/dubbo-go-samples/configcenter/apollo/go-client/cmd" /> - <directory value="$PROJECT_DIR$" /> - <method v="2" /> - </configuration> -</component> + <configuration default="false" name="configcenter-apollo-client" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="v3config-configcenter" singleton="true"> + <module name="dubbo-go-samples" /> + <working_directory value="$PROJECT_DIR$/configcenter/apollo/go-client" /> + <envs> + <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/configcenter/apollo/go-client/conf/dubbogo.yml" /> + </envs> + <kind value="PACKAGE" /> + <package value="github.com/apache/dubbo-go-samples/configcenter/apollo/go-client/cmd" /> + <directory value="$PROJECT_DIR$" /> + <filePath value="$PROJECT_DIR$/configcenter/apollo/go-client/cmd/client.go" /> + <method v="2" /> + </configuration> +</component> \ No newline at end of file diff --git a/.run/configcenter/configcenter-apollo-server.run.xml b/.run/configcenter/configcenter-apollo-server.run.xml index 3384df6..de38711 100644 --- a/.run/configcenter/configcenter-apollo-server.run.xml +++ b/.run/configcenter/configcenter-apollo-server.run.xml @@ -1,15 +1,14 @@ <component name="ProjectRunConfigurationManager"> - <configuration default="false" name="configcenter-apollo-server" type="GoApplicationRunConfiguration" factoryName="Go Application" singleton="false"> - <module name="dubbo-go-samples" /> - <working_directory value="$PROJECT_DIR$" /> - <envs> - <env name="CONF_PROVIDER_FILE_PATH" value="$PROJECT_DIR$/configcenter/apollo/go-server/conf/server.yml" /> - <env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/configcenter/apollo/go-server/conf/log.yml" /> - </envs> - <kind value="PACKAGE" /> - <filePath value="$PROJECT_DIR$/configcenter/apollo/go-server/cmd/server.go" /> - <package value="github.com/apache/dubbo-go-samples/configcenter/apollo/go-server/cmd" /> - <directory value="$PROJECT_DIR$" /> - <method v="2" /> - </configuration> -</component> + <configuration default="false" name="configcenter-apollo-server" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="v3config-configcenter" singleton="true"> + <module name="dubbo-go-samples" /> + <working_directory value="$PROJECT_DIR$/configcenter/apollo/go-server" /> + <envs> + <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/configcenter/apollo/go-server/conf/dubbogo.yml" /> + </envs> + <kind value="PACKAGE" /> + <package value="github.com/apache/dubbo-go-samples/configcenter/apollo/go-server/cmd" /> + <directory value="$PROJECT_DIR$" /> + <filePath value="$PROJECT_DIR$/configcenter/apollo/go-client/cmd/server.go" /> + <method v="2" /> + </configuration> +</component> \ No newline at end of file diff --git a/.run/configcenter/configcenter-apollo-test.run.xml b/.run/configcenter/configcenter-apollo-test.run.xml index 36035f1..1bfcf2b 100644 --- a/.run/configcenter/configcenter-apollo-test.run.xml +++ b/.run/configcenter/configcenter-apollo-test.run.xml @@ -1,15 +1,14 @@ <component name="ProjectRunConfigurationManager"> - <configuration default="false" name="configcenter-apollo-test" type="GoTestRunConfiguration" factoryName="Go Test"> + <configuration default="false" name="configcenter-apollo-test" type="GoTestRunConfiguration" factoryName="Go Test" > <module name="dubbo-go-samples" /> - <working_directory value="$PROJECT_DIR$/configcenter/apollo" /> + <working_directory value="$PROJECT_DIR$/integrate_test/configcenter/apollo" /> <useCustomBuildTags value="true" /> <envs> - <env name="CONF_CONSUMER_FILE_PATH" value="go-server/conf/client.yml" /> - <env name="APP_LOG_CONF_FILE" value="go-server/conf/log.yml" /> + <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/configcenter/apollo/go-server/conf/dubbogo.yml" /> </envs> <framework value="gotest" /> <kind value="PACKAGE" /> - <package value="github.com/apache/dubbo-go-samples/configcenter/apollo/go-server/tests/integration" /> + <package value="github.com/apache/dubbo-go-samples/integrate_test/configcenter/apollo/tests/integration" /> <directory value="$PROJECT_DIR$" /> <filePath value="$PROJECT_DIR$" /> <method v="2" /> diff --git a/.run/helloworld-go-server.run.xml b/.run/helloworld-go-server.run.xml deleted file mode 100644 index 12a75d0..0000000 --- a/.run/helloworld-go-server.run.xml +++ /dev/null @@ -1,14 +0,0 @@ -<component name="ProjectRunConfigurationManager"> - <configuration default="false" name="helloworld-go-server" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="v3config-helloworld" singleton="true"> - <module name="dubbo-go-samples" /> - <working_directory value="$PROJECT_DIR$" /> - <envs> - <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/helloworld/go-server/conf/dubbogo.yml" /> - </envs> - <kind value="PACKAGE" /> - <package value="github.com/apache/dubbo-go-samples/helloworld/go-server/cmd" /> - <directory value="$PROJECT_DIR$" /> - <filePath value="$PROJECT_DIR$/helloworld/go-client/cmd/client.go" /> - <method v="2" /> - </configuration> -</component> \ No newline at end of file diff --git a/configcenter/apollo/README.md b/configcenter/apollo/README.md new file mode 100644 index 0000000..7ff6697 --- /dev/null +++ b/configcenter/apollo/README.md @@ -0,0 +1,64 @@ +# Apollo config center example + + +## Instructions + + +### go-server start + +1. Create new apollo server namespace for yaml format + +2. Add provider config content +```yaml +dubbo: + application: + name: "demo-server" + version: "2.0" + registries: + "demoZK": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + protocols: + "triple": + name: "tri" + port: 20000 + provider: + registry: + - demoZK + services: + "greeterImpl": + protocol: "triple" + interface: "com.apache.dubbo.sample.basic.IGreeter" # must be compatible with grpc or dubbo-java +``` + +3. Start provider server + +### go-client start + +1. Create new apollo client namespace for yaml format + +2. Add client config content + +```yaml +dubbo: + registries: + "demoZK": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + consumer: + registry: + - demoZK + references: + "greeterImpl": + protocol: "tri" + interface: "com.apache.dubbo.sample.basic.IGreeter" # must be compatible with grpc or dubbo-java +``` + +3. Start provider server + + + + + diff --git a/configcenter/apollo/README_zh.md b/configcenter/apollo/README_zh.md new file mode 100644 index 0000000..6fd7a14 --- /dev/null +++ b/configcenter/apollo/README_zh.md @@ -0,0 +1,60 @@ +# Apollo 配置中心示例 + + +## 介绍 + + +### go-server 启动 + +1. 创建新的apollo服务端yaml格式的namespace + +2. 添加服务端配置内容 + +```yaml +dubbo: + application: + name: "demo-server" + version: "2.0" + registries: + "demoZK": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + protocols: + "triple": + name: "tri" + port: 20000 + provider: + registry: + - demoZK + services: + "greeterImpl": + protocol: "triple" + interface: "com.apache.dubbo.sample.basic.IGreeter" # must be compatible with grpc or dubbo-java +``` + +3. 启动go-server + +### go-client 启动 + +1. 创建新的apollo客户端yaml格式的namespace + +2. 添加客户端配置内容 + +```yaml +dubbo: + registries: + "demoZK": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + consumer: + registry: + - demoZK + references: + "greeterImpl": + protocol: "tri" + interface: "com.apache.dubbo.sample.basic.IGreeter" # must be compatible with grpc or dubbo-java +``` + +3. 启动go-client \ No newline at end of file diff --git a/configcenter/apollo/go-client/cmd/client.go b/configcenter/apollo/go-client/cmd/client.go index 37c1b05..68fe2c0 100644 --- a/configcenter/apollo/go-client/cmd/client.go +++ b/configcenter/apollo/go-client/cmd/client.go @@ -19,50 +19,37 @@ package main import ( "context" - "os" "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/config_center/apollo" - _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl" - _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" - _ "dubbo.apache.org/dubbo-go/v3/registry/protocol" - _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper" - - hessian "github.com/apache/dubbo-go-hessian2" - - "github.com/dubbogo/gost/log" + _ "dubbo.apache.org/dubbo-go/v3/imports" ) import ( - "github.com/apache/dubbo-go-samples/configcenter/apollo/go-client/pkg" + "github.com/apache/dubbo-go-samples/api" ) -var userProvider = new(pkg.UserProvider) +var grpcGreeterImpl = new(api.GreeterClientImpl) func init() { - config.SetConsumerService(userProvider) - hessian.RegisterPOJO(&pkg.User{}) + config.SetConsumerService(grpcGreeterImpl) } -// need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run +// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-client/conf/dubbogo.yml 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) - if err != nil { - gxlog.CError("error: %v\n", err) - os.Exit(1) - return + logger.Info("start to test dubbo") + req := &api.HelloRequest{ + Name: "laurence", + } + reply := &api.User{} + if err := grpcGreeterImpl.SayHello(context.Background(), req, reply); err != nil { + logger.Error(err) } - gxlog.CInfo("response result: %v\n", user) + logger.Infof("client response result: %v\n", reply) } diff --git a/configcenter/apollo/go-client/conf/client.yml b/configcenter/apollo/go-client/conf/client.yml deleted file mode 100644 index 5b8c6c0..0000000 --- a/configcenter/apollo/go-client/conf/client.yml +++ /dev/null @@ -1,66 +0,0 @@ -# dubbo client yaml configure file - -check: true -# client -request_timeout: "3s" -# connect timeout -connect_timeout: "3s" - -# config center config -config_center: - protocol: apollo - address: 127.0.0.1:8080 - app_id: UserInfoClient - cluster: dev - -# application config -application: - organization: "dubbo.io" - name: "user-info-client" - module: "dubbo-go user-info client" - version: "0.0.1" - environment: "dev" - -# registry config -registries: - "demoZk": - protocol: "zookeeper" - timeout: "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - -# reference config -references: - "UserProvider": - registry: "demoZk" - 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/configcenter/apollo/go-client/conf/dubbogo.yml b/configcenter/apollo/go-client/conf/dubbogo.yml new file mode 100644 index 0000000..c147f2e --- /dev/null +++ b/configcenter/apollo/go-client/conf/dubbogo.yml @@ -0,0 +1,7 @@ +dubbo: + config-center: + protocol: "apollo" + address: "localhost:8080" + app-id: "demo_server" + cluster: "default" + namespace: "demo-client-config" diff --git a/configcenter/apollo/go-client/conf/log.yml b/configcenter/apollo/go-client/conf/log.yml deleted file mode 100644 index d0400fe..0000000 --- a/configcenter/apollo/go-client/conf/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "debug" -development: true -disableCaller: false -disableStacktrace: false -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capital" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/configcenter/apollo/go-client/pkg/user.go b/configcenter/apollo/go-client/pkg/user.go deleted file mode 100644 index 7733ea4..0000000 --- a/configcenter/apollo/go-client/pkg/user.go +++ /dev/null @@ -1,42 +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" - "time" -) - -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/configcenter/apollo/go-server/cmd/server.go b/configcenter/apollo/go-server/cmd/server.go index e8adb2b..7e54974 100644 --- a/configcenter/apollo/go-server/cmd/server.go +++ b/configcenter/apollo/go-server/cmd/server.go @@ -18,6 +18,7 @@ package main import ( + "context" "fmt" "os" "os/signal" @@ -26,33 +27,35 @@ 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/config_center/apollo" - _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl" - _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" - _ "dubbo.apache.org/dubbo-go/v3/registry/protocol" - _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper" - - hessian "github.com/apache/dubbo-go-hessian2" + _ "dubbo.apache.org/dubbo-go/v3/imports" ) import ( - "github.com/apache/dubbo-go-samples/configcenter/apollo/go-server/pkg" + "github.com/apache/dubbo-go-samples/api" ) var ( survivalTimeout = int(3e9) ) -// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run -func main() { - hessian.RegisterPOJO(&pkg.User{}) - config.Load() +type GreeterProvider struct { + api.GreeterProviderBase +} + +func (s *GreeterProvider) SayHello(ctx context.Context, in *api.HelloRequest) (*api.User, error) { + logger.Infof("Dubbo3 GreeterProvider get user name = %s\n", in.Name) + return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil +} + +func main() { + config.SetProviderService(&GreeterProvider{}) + err := config.Load() + if err != nil { + panic(err) + } initSignal() } diff --git a/configcenter/apollo/go-server/conf/client.yml b/configcenter/apollo/go-server/conf/client.yml deleted file mode 100644 index 8a1bf33..0000000 --- a/configcenter/apollo/go-server/conf/client.yml +++ /dev/null @@ -1,66 +0,0 @@ -# dubbo client yaml configure file - -check: true -# client -request_timeout: "3s" -# connect timeout -connect_timeout: "3s" - -# config center config -config_center: - protocol: apollo - address: 127.0.0.1:8080 - app_id: UserInfoTest - cluster: dev - -# application config -application: - organization: "dubbo.io" - name: "user-info-client" - module: "dubbo-go user-info client" - version: "0.0.1" - environment: "dev" - -# registry config -registries: - "demoZk": - protocol: "zookeeper" - timeout: "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - -# reference config -references: - "UserProvider": - registry: "demoZk" - 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/configcenter/apollo/go-server/conf/dubbogo.yml b/configcenter/apollo/go-server/conf/dubbogo.yml new file mode 100644 index 0000000..0b09dab --- /dev/null +++ b/configcenter/apollo/go-server/conf/dubbogo.yml @@ -0,0 +1,7 @@ +dubbo: + config-center: + protocol: "apollo" + address: "localhost:8080" + app-id: "demo_server" + cluster: "default" + namespace: "demo-provider-config" diff --git a/configcenter/apollo/go-server/conf/log.yml b/configcenter/apollo/go-server/conf/log.yml deleted file mode 100644 index a75bccb..0000000 --- a/configcenter/apollo/go-server/conf/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "error" -development: true -disableCaller: false -disableStacktrace: false -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capital" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/configcenter/apollo/go-server/conf/server.yml b/configcenter/apollo/go-server/conf/server.yml deleted file mode 100644 index 5053ec5..0000000 --- a/configcenter/apollo/go-server/conf/server.yml +++ /dev/null @@ -1,62 +0,0 @@ -# dubbo server yaml configure file - -# config center config -config_center: - protocol: apollo - address: 127.0.0.1:8080 - app_id: UserInfoServer - cluster: dev - -# application config -application: - organization: "dubbo.io" - name: "user-info-server" - module: "dubbo-go user-info server" - version: "0.0.1" - environment: "dev" - -# registry config -registries: - "demoZk": - protocol: "zookeeper" - timeout: "3s" - address: "127.0.0.1:2181" - -# service config -services: - "UserProvider": - registry: "demoZk" - 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/configcenter/apollo/go-server/pkg/user.go b/configcenter/apollo/go-server/pkg/user.go deleted file mode 100644 index 75d0916..0000000 --- a/configcenter/apollo/go-server/pkg/user.go +++ /dev/null @@ -1,62 +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" - "time" -) - -import ( - "dubbo.apache.org/dubbo-go/v3/config" - - hessian "github.com/apache/dubbo-go-hessian2" - - "github.com/dubbogo/gost/log" -) - -func init() { - config.SetProviderService(new(UserProvider)) - // ------for hessian2------ - hessian.RegisterPOJO(&User{}) -} - -type User struct { - ID string - Name string - Age int32 - Time time.Time -} - -type UserProvider struct { -} - -func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*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/go.mod b/go.mod index 550d8f4..d9d33bc 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,8 @@ require ( k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a // indirect ) -replace github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.8.0 +replace ( + github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.8.0 +) go 1.13 diff --git a/configcenter/apollo/go-server/docker/docker-compose.yml b/integrate_test/configcenter/apollo/docker/docker-compose.yml similarity index 100% rename from configcenter/apollo/go-server/docker/docker-compose.yml rename to integrate_test/configcenter/apollo/docker/docker-compose.yml diff --git a/configcenter/apollo/go-server/docker/docker-health-check.sh b/integrate_test/configcenter/apollo/docker/docker-health-check.sh similarity index 100% rename from configcenter/apollo/go-server/docker/docker-health-check.sh rename to integrate_test/configcenter/apollo/docker/docker-health-check.sh diff --git a/configcenter/apollo/go-server/docker/sql/apolloconfigdb.sql b/integrate_test/configcenter/apollo/docker/sql/apolloconfigdb.sql similarity index 100% rename from configcenter/apollo/go-server/docker/sql/apolloconfigdb.sql rename to integrate_test/configcenter/apollo/docker/sql/apolloconfigdb.sql diff --git a/configcenter/apollo/go-server/docker/sql/apolloportaldb.sql b/integrate_test/configcenter/apollo/docker/sql/apolloportaldb.sql similarity index 100% rename from configcenter/apollo/go-server/docker/sql/apolloportaldb.sql rename to integrate_test/configcenter/apollo/docker/sql/apolloportaldb.sql diff --git a/configcenter/apollo/go-server/tests/integration/userprovider_test.go b/integrate_test/configcenter/apollo/tests/integration/greeterProvider_test.go similarity index 67% rename from configcenter/apollo/go-server/tests/integration/userprovider_test.go rename to integrate_test/configcenter/apollo/tests/integration/greeterProvider_test.go index 7183e64..992c55d 100644 --- a/configcenter/apollo/go-server/tests/integration/userprovider_test.go +++ b/integrate_test/configcenter/apollo/tests/integration/greeterProvider_test.go @@ -28,12 +28,24 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGetUser(t *testing.T) { - user := &User{} - err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user) +import ( + dubbo3pb "github.com/apache/dubbo-go-samples/api" +) + +func TestSayHello(t *testing.T) { + req := &dubbo3pb.HelloRequest{ + Name: "laurence", + } + + reply := &dubbo3pb.User{} + + ctx := context.Background() + ctx = context.WithValue(ctx, "tri-req-id", "test_value_XXXXXXXX") + + err := greeterProvider.SayHello(ctx, req, reply) + assert.Nil(t, err) - assert.Equal(t, "A001", user.ID) - assert.Equal(t, "Alex Stocks", user.Name) - assert.Equal(t, int32(18), user.Age) - assert.NotNil(t, user.Time) + assert.Equal(t, "Hello laurence", reply.Name) + assert.Equal(t, "12345", reply.Id) + assert.Equal(t, int32(21), reply.Age) } diff --git a/configcenter/apollo/go-server/tests/integration/main_test.go b/integrate_test/configcenter/apollo/tests/integration/main_test.go similarity index 73% rename from configcenter/apollo/go-server/tests/integration/main_test.go rename to integrate_test/configcenter/apollo/tests/integration/main_test.go index a5c1729..d8a0568 100644 --- a/configcenter/apollo/go-server/tests/integration/main_test.go +++ b/integrate_test/configcenter/apollo/tests/integration/main_test.go @@ -20,7 +20,6 @@ package integration import ( - "context" "os" "testing" "time" @@ -31,42 +30,23 @@ import ( _ "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/config_center/apollo" _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl" _ "dubbo.apache.org/dubbo-go/v3/metadata/service/local" _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" _ "dubbo.apache.org/dubbo-go/v3/registry/protocol" _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper" +) - hessian "github.com/apache/dubbo-go-hessian2" +import ( + dubbo3pb "github.com/apache/dubbo-go-samples/api" ) -var userProvider = new(UserProvider) +var greeterProvider = new(dubbo3pb.GreeterClientImpl) func TestMain(m *testing.M) { - config.SetConsumerService(userProvider) - hessian.RegisterPOJO(&User{}) + config.SetConsumerService(greeterProvider) 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/rpc/dubbo3/pb/dubbogo-grpc/server/dubbogo-server/tests/integration/userprovider_test.go b/rpc/dubbo3/pb/dubbogo-grpc/server/dubbogo-server/tests/integration/userprovider_test.go index 8100011..6148859 100644 --- a/rpc/dubbo3/pb/dubbogo-grpc/server/dubbogo-server/tests/integration/userprovider_test.go +++ b/rpc/dubbo3/pb/dubbogo-grpc/server/dubbogo-server/tests/integration/userprovider_test.go @@ -34,7 +34,7 @@ import ( import ( dubbo3pb "github.com/apache/dubbo-go-samples/general/dubbo3/pb/dubbogo-grpc/protobuf/dubbo3" - grpcpb "github.com/apache/dubbo-go-samples/general/dubbo3/pb/dubbogo-grpc/server/dubbogo-server/tests/integration/grpc_test_proto" + grpcpb "github.com/apache/dubbo-go-samples/general/dubbo3/pb/dubbogo-grpc/server/dubbogo-server/tests/integration/grpc_test_proto" ) func TestSayHello(t *testing.T) { @@ -51,8 +51,7 @@ func TestSayHello(t *testing.T) { assert.Equal(t, int32(21), user.Age) } - -func TestStreamSayHello(t *testing.T){ +func TestStreamSayHello(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, tripleConstant.TripleCtxKey(tripleConstant.TripleRequestID), "triple-request-id-demo") req := dubbo3pb.HelloRequest{ @@ -70,18 +69,18 @@ func TestStreamSayHello(t *testing.T){ rspUser := &dubbo3pb.User{} err = r.RecvMsg(rspUser) assert.Nil(t, err) - assert.Equal(t, "hello laurence",rspUser.Name) - assert.Equal(t, "123456789",rspUser.Id) - assert.Equal(t, int32(18),rspUser.Age) + assert.Equal(t, "hello laurence", rspUser.Name) + assert.Equal(t, "123456789", rspUser.Id) + assert.Equal(t, int32(18), rspUser.Age) err = r.Send(&req) assert.Nil(t, err) err = r.RecvMsg(rspUser) assert.Nil(t, err) - assert.Equal(t, "hello laurence",rspUser.Name) - assert.Equal(t, "123456789",rspUser.Id) - assert.Equal(t, int32(19),rspUser.Age) + assert.Equal(t, "hello laurence", rspUser.Name) + assert.Equal(t, "123456789", rspUser.Id) + assert.Equal(t, int32(19), rspUser.Age) } func TestGRPCClientHello(t *testing.T) { @@ -102,7 +101,7 @@ func TestGRPCClientHello(t *testing.T) { assert.Equal(t, int32(21), rsp.Age) } -func TestGRPCClientStreamSayHello(t *testing.T){ +func TestGRPCClientStreamSayHello(t *testing.T) { conn, err := grpc.Dial("127.0.0.1:20001", grpc.WithInsecure()) assert.Nil(t, err) defer conn.Close() @@ -121,18 +120,16 @@ func TestGRPCClientStreamSayHello(t *testing.T){ rspUser := &grpcpb.User{} err = clientStream.RecvMsg(rspUser) assert.Nil(t, err) - assert.Equal(t, "hello grpc laurence",rspUser.Name) - assert.Equal(t, "123456789",rspUser.Id) - assert.Equal(t, int32(18),rspUser.Age) + assert.Equal(t, "hello grpc laurence", rspUser.Name) + assert.Equal(t, "123456789", rspUser.Id) + assert.Equal(t, int32(18), rspUser.Age) err = clientStream.Send(req) assert.Nil(t, err) err = clientStream.RecvMsg(rspUser) assert.Nil(t, err) - assert.Equal(t, "hello grpc laurence",rspUser.Name) - assert.Equal(t, "123456789",rspUser.Id) - assert.Equal(t, int32(19),rspUser.Age) + assert.Equal(t, "hello grpc laurence", rspUser.Name) + assert.Equal(t, "123456789", rspUser.Id) + assert.Equal(t, int32(19), rspUser.Age) } - -
