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 7b0d9e79774c0227bd868ac1c459d8393884589f Author: Mulavar <[email protected]> AuthorDate: Sat Aug 28 09:06:55 2021 +0800 update nacos samples config (#205) Co-authored-by: dongjianhui03 <[email protected]> --- .run/registry/registry-nacos-go-client.run.xml | 4 +- .run/registry/registry-nacos-go-server.run.xml | 4 +- registry/nacos/go-client/cmd/client.go | 27 +++++++---- registry/nacos/go-client/conf/client.yml | 57 ----------------------- registry/nacos/go-client/conf/dubbogo.yml | 13 ++++++ registry/nacos/go-client/pkg/user.go | 42 ----------------- registry/nacos/go-server/cmd/server.go | 38 ++++++++++++++-- registry/nacos/go-server/conf/client.yml | 57 ----------------------- registry/nacos/go-server/conf/dubbogo.yml | 17 +++++++ registry/nacos/go-server/conf/server.yml | 55 ----------------------- registry/nacos/go-server/pkg/user.go | 62 -------------------------- 11 files changed, 88 insertions(+), 288 deletions(-) diff --git a/.run/registry/registry-nacos-go-client.run.xml b/.run/registry/registry-nacos-go-client.run.xml index 35bef0d..d720d09 100644 --- a/.run/registry/registry-nacos-go-client.run.xml +++ b/.run/registry/registry-nacos-go-client.run.xml @@ -3,13 +3,13 @@ <module name="dubbo-go-samples" /> <working_directory value="$PROJECT_DIR$" /> <envs> - <env name="CONF_CONSUMER_FILE_PATH" value="$PROJECT_DIR$/registry/nacos/go-client/conf/client.yml" /> + <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/registry/nacos/go-client/conf/dubbogo.yml" /> <env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/general/registry/nacos/go-client/conf/log.yml" /> </envs> <kind value="PACKAGE" /> - <filePath value="$PROJECT_DIR$/general/grpc/unary/go-client/cmd/client.go" /> <package value="github.com/apache/dubbo-go-samples/registry/nacos/go-client/cmd" /> <directory value="$PROJECT_DIR$" /> + <filePath value="$PROJECT_DIR$/general/grpc/unary/go-client/cmd/client.go" /> <method v="2" /> </configuration> </component> \ No newline at end of file diff --git a/.run/registry/registry-nacos-go-server.run.xml b/.run/registry/registry-nacos-go-server.run.xml index 80a04bf..fb5f292 100644 --- a/.run/registry/registry-nacos-go-server.run.xml +++ b/.run/registry/registry-nacos-go-server.run.xml @@ -4,12 +4,12 @@ <working_directory value="$PROJECT_DIR$" /> <envs> <env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/registry/nacos/go-server/conf/log.yml" /> - <env name="CONF_PROVIDER_FILE_PATH" value="$PROJECT_DIR$/registry/nacos/go-server/conf/server.yml" /> + <env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/registry/nacos/go-server/conf/dubbogo.yml" /> </envs> <kind value="PACKAGE" /> - <filePath value="$PROJECT_DIR$/general/registry/nacos/go-server/cmd/server.go" /> <package value="github.com/apache/dubbo-go-samples/registry/nacos/go-server/cmd" /> <directory value="$PROJECT_DIR$" /> + <filePath value="$PROJECT_DIR$/general/registry/nacos/go-server/cmd/server.go" /> <method v="2" /> </configuration> </component> \ No newline at end of file diff --git a/registry/nacos/go-client/cmd/client.go b/registry/nacos/go-client/cmd/client.go index 5369454..5412757 100644 --- a/registry/nacos/go-client/cmd/client.go +++ b/registry/nacos/go-client/cmd/client.go @@ -38,24 +38,35 @@ import ( "github.com/dubbogo/gost/log" ) -import ( - "github.com/apache/dubbo-go-samples/registry/nacos/go-client/pkg" -) +type UserProvider struct { + GetUser func(ctx context.Context, req []interface{}, rsp *User) error +} + +func (u *UserProvider) Reference() string { + return "userProvider" +} -var userProvider = new(pkg.UserProvider) +type User struct { + ID string + Name string + Age int32 + Time time.Time +} -func init() { - config.SetConsumerService(userProvider) - hessian.RegisterPOJO(&pkg.User{}) +func (*User) JavaClassName() string { + return "org.apache.dubbo.User" } // need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run func main() { + var userProvider = &UserProvider{} + config.SetConsumerService(userProvider) + hessian.RegisterPOJO(&User{}) config.Load() time.Sleep(3 * time.Second) gxlog.CInfo("\n\n\nstart to test dubbo") - user := &pkg.User{} + user := &User{} err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user) if err != nil { gxlog.CError("error: %v\n", err) diff --git a/registry/nacos/go-client/conf/client.yml b/registry/nacos/go-client/conf/client.yml deleted file mode 100644 index 5936848..0000000 --- a/registry/nacos/go-client/conf/client.yml +++ /dev/null @@ -1,57 +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: - "demoNacos": - protocol: "nacos" - timeout: "3s" - address: "127.0.0.1:8848" - -# reference config -references: - "UserProvider": - registry: "demoNacos" - 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/nacos/go-client/conf/dubbogo.yml b/registry/nacos/go-client/conf/dubbogo.yml new file mode 100644 index 0000000..a3eafaa --- /dev/null +++ b/registry/nacos/go-client/conf/dubbogo.yml @@ -0,0 +1,13 @@ +dubbo: + registries: + "demoNacos": + protocol: "nacos" + timeout: "3s" + address: "127.0.0.1:8848" + consumer: + registry: + - demoNacos + references: + "userProvider": + protocol: "dubbo" + interface: "org.apache.dubbo.UserProvider" \ No newline at end of file diff --git a/registry/nacos/go-client/pkg/user.go b/registry/nacos/go-client/pkg/user.go deleted file mode 100644 index 7733ea4..0000000 --- a/registry/nacos/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/registry/nacos/go-server/cmd/server.go b/registry/nacos/go-server/cmd/server.go index b08f26d..1670192 100644 --- a/registry/nacos/go-server/cmd/server.go +++ b/registry/nacos/go-server/cmd/server.go @@ -18,6 +18,7 @@ package main import ( + "context" "fmt" "os" "os/signal" @@ -35,16 +36,47 @@ import ( _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" _ "dubbo.apache.org/dubbo-go/v3/registry/nacos" _ "dubbo.apache.org/dubbo-go/v3/registry/protocol" -) -import ( - _ "github.com/apache/dubbo-go-samples/registry/nacos/go-server/pkg" + hessian "github.com/apache/dubbo-go-hessian2" + + gxlog "github.com/dubbogo/gost/log" ) var ( survivalTimeout = int(3e9) ) +func init() { + config.SetProviderService(&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" +} + // need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run func main() { config.Load() diff --git a/registry/nacos/go-server/conf/client.yml b/registry/nacos/go-server/conf/client.yml deleted file mode 100644 index d9e9c87..0000000 --- a/registry/nacos/go-server/conf/client.yml +++ /dev/null @@ -1,57 +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: - "nacos": - protocol: "nacos" - timeout: "3s" - address: "127.0.0.1:8848" - -# reference config -references: - "UserProvider": - registry: "nacos" - 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/nacos/go-server/conf/dubbogo.yml b/registry/nacos/go-server/conf/dubbogo.yml new file mode 100644 index 0000000..d485271 --- /dev/null +++ b/registry/nacos/go-server/conf/dubbogo.yml @@ -0,0 +1,17 @@ +dubbo: + registries: + "demoNacos": + protocol: "nacos" + timeout: "3s" + address: "127.0.0.1:8848" + protocols: + "dubbo": + name: "dubbo" + port: 20000 + provider: + registry: + - demoNacos + services: + "userProvider": + protocol: "dubbo" + interface: "org.apache.dubbo.UserProvider" \ No newline at end of file diff --git a/registry/nacos/go-server/conf/server.yml b/registry/nacos/go-server/conf/server.yml deleted file mode 100644 index 441c344..0000000 --- a/registry/nacos/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: - "demoNacos": - protocol: "nacos" - timeout : "3s" - address: "127.0.0.1:8848" - -# service config -services: - "UserProvider": - registry: "demoNacos" - 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/nacos/go-server/pkg/user.go b/registry/nacos/go-server/pkg/user.go deleted file mode 100644 index 75d0916..0000000 --- a/registry/nacos/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" -}
