Merge pull request #10 from DogBaoBao/feature/standard
Add service both consumer and provider
diff --git a/golang/README.md b/golang/README.md
index d650cb8..f9af481 100644
--- a/golang/README.md
+++ b/golang/README.md
@@ -48,7 +48,15 @@
* router
Some router examples. Now, a condition router example is existing.
-
+
+* seata
+
+ Transaction system examples by seata.
+
+* shop
+
+ Shop sample, make consumer and provider run in a go program.
+
* tracing
Some tracing examples. We have tracing support of dubbo/grpc/jsonrpc protocol at present.
diff --git a/golang/shop/dubbo/go-service-order/app/order.go b/golang/shop/dubbo/go-service-order/app/order.go
new file mode 100644
index 0000000..9f6074c
--- /dev/null
+++ b/golang/shop/dubbo/go-service-order/app/order.go
@@ -0,0 +1,74 @@
+/*
+ * 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 (
+ "github.com/apache/dubbo-go/config"
+)
+
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+var (
+ orderProvider = new(OrderProvider)
+)
+
+func init() {
+ config.SetProviderService(orderProvider)
+ hessian.RegisterPOJO(&Order{})
+}
+
+type Order struct {
+ Id string
+ Name string
+ Price int
+ Count int
+ Product Product
+}
+
+func (Order) JavaClassName() string {
+ return "com.ikurento.order.Order"
+}
+
+type OrderProvider struct{}
+
+func (o *OrderProvider) GetOrder(ctx context.Context, req []interface{}) (*Order, error) {
+ println("req:%#v", req)
+
+ product := &Product{}
+ err := productProvider.GetProduct(context.TODO(), []interface{}{"A001"}, product)
+ if err != nil {
+ panic(err)
+ }
+ println("response from product result: %v\n", product)
+
+ rsp := Order{
+ "A001", "A001", 200, 2, *product}
+
+ println("rsp:%#v", rsp)
+ return &rsp, nil
+}
+
+func (o *OrderProvider) Reference() string {
+ return "OrderProvider"
+}
diff --git a/golang/shop/dubbo/go-service-order/app/product.go b/golang/shop/dubbo/go-service-order/app/product.go
new file mode 100644
index 0000000..3527853
--- /dev/null
+++ b/golang/shop/dubbo/go-service-order/app/product.go
@@ -0,0 +1,58 @@
+/*
+ * 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 (
+ "github.com/apache/dubbo-go/config"
+)
+
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+var (
+ productProvider = new(ProductProvider)
+)
+
+func init() {
+ config.SetConsumerService(productProvider)
+ // ------for hessian2------
+ hessian.RegisterPOJO(&Product{})
+}
+
+type Product struct {
+ Id string
+ Price int
+ Quantity int
+}
+
+func (Product) JavaClassName() string {
+ return "com.ikurento.product.Product"
+}
+
+type ProductProvider struct {
+ GetProduct func(ctx context.Context, req []interface{}, rsp *Product) error
+}
+
+func (u *ProductProvider) Reference() string {
+ return "ProductProvider"
+}
diff --git a/golang/shop/dubbo/go-service-order/app/service.go b/golang/shop/dubbo/go-service-order/app/service.go
new file mode 100755
index 0000000..66209c3
--- /dev/null
+++ b/golang/shop/dubbo/go-service-order/app/service.go
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/signal"
+ "syscall"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go/common/logger"
+ "github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+)
+
+var (
+ survivalTimeout = int(3e9)
+)
+
+// they are necessary:
+// export CONF_PROVIDER_FILE_PATH="xxx"
+// export CONF_CONSUMER_FILE_PATH="xxx"
+// export APP_LOG_CONF_FILE="xxx"
+func main() {
+ config.Load()
+
+ initSignal()
+}
+
+func initSignal() {
+ signals := make(chan os.Signal, 1)
+ // It is not possible to block SIGKILL or syscall.SIGSTOP
+ signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
+ for {
+ sig := <-signals
+ logger.Infof("get signal %s", sig.String())
+ switch sig {
+ case syscall.SIGHUP:
+ // reload()
+ default:
+ time.AfterFunc(time.Duration(survivalTimeout), func() {
+ logger.Warnf("app exit now by force...")
+ os.Exit(1)
+ })
+
+ // The program exits normally or timeout forcibly exits.
+ fmt.Println("provider app exit now...")
+ return
+ }
+ }
+}
diff --git a/golang/shop/dubbo/go-service-order/app/version.go b/golang/shop/dubbo/go-service-order/app/version.go
new file mode 100755
index 0000000..b272a8d
--- /dev/null
+++ b/golang/shop/dubbo/go-service-order/app/version.go
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import "fmt"
+
+var (
+ Version = "2.7.7"
+)
+
+func println(format string, args ...interface{}) {
+ fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...)
+}
\ No newline at end of file
diff --git a/golang/shop/dubbo/go-service-order/profiles/client.yml b/golang/shop/dubbo/go-service-order/profiles/client.yml
new file mode 100755
index 0000000..e53b00f
--- /dev/null
+++ b/golang/shop/dubbo/go-service-order/profiles/client.yml
@@ -0,0 +1,65 @@
+# dubbo client yaml configure file
+
+
+check: true
+# client
+request_timeout: "3s"
+# connect timeout
+connect_timeout: "3s"
+
+# application config
+application:
+ organization: "ikurento.com"
+ name: "BDTService"
+ module: "dubbogo order-info client"
+ version: "0.0.1"
+ owner: "ZX"
+ environment: "dev"
+
+registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2181"
+ username: ""
+ password: ""
+
+references:
+ "ProductProvider":
+ group: dg
+ version: 1.0.0
+ # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ registry: "demoZk"
+ protocol: "dubbo"
+ # 相当于dubbo.xml中的interface
+ interface: "com.ikurento.product.ProductProvider"
+ loadbalance: "random"
+ warmup: "100"
+ cluster: "failover"
+ methods:
+ - name: "GetProduct"
+ retries: 3
+ loadbalance: "random"
+
+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/golang/shop/dubbo/go-service-order/profiles/log.yml b/golang/shop/dubbo/go-service-order/profiles/log.yml
new file mode 100755
index 0000000..3ed242d
--- /dev/null
+++ b/golang/shop/dubbo/go-service-order/profiles/log.yml
@@ -0,0 +1,28 @@
+
+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: "capitalColor"
+ timeEncoder: "iso8601"
+ durationEncoder: "seconds"
+ callerEncoder: "short"
+ nameEncoder: ""
+
+outputPaths:
+ - "stderr"
+errorOutputPaths:
+ - "stderr"
+initialFields:
diff --git a/golang/shop/dubbo/go-service-order/profiles/server.yml b/golang/shop/dubbo/go-service-order/profiles/server.yml
new file mode 100755
index 0000000..5a0de50
--- /dev/null
+++ b/golang/shop/dubbo/go-service-order/profiles/server.yml
@@ -0,0 +1,58 @@
+# dubbo server yaml configure file
+
+
+# application config
+application:
+ organization: "ikurento.com"
+ name: "BDTService"
+ module: "dubbogo order-info server"
+ version: "0.0.1"
+ owner: "ZX"
+ environment: "dev"
+
+registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2181"
+
+services:
+ "OrderProvider":
+ group: dg
+ version: 1.0.0
+ # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ registry: "demoZk"
+ protocol: "dubbo"
+ # 相当于dubbo.xml中的interface
+ interface: "com.ikurento.order.OrderProvider"
+ loadbalance: "random"
+ warmup: "100"
+ cluster: "failover"
+ methods:
+ - name: "GetOrder"
+ retries: 3
+ loadbalance: "random"
+
+protocols:
+ "dubbo":
+ name: "dubbo"
+ port: 20001
+
+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/golang/shop/dubbo/go-service-product/app/product.go b/golang/shop/dubbo/go-service-product/app/product.go
new file mode 100644
index 0000000..44457db
--- /dev/null
+++ b/golang/shop/dubbo/go-service-product/app/product.go
@@ -0,0 +1,67 @@
+/*
+ * 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"
+ "fmt"
+)
+
+import (
+ "github.com/apache/dubbo-go/config"
+)
+
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+var (
+ productProvider = new(ProductProvider)
+)
+
+func init() {
+ config.SetProviderService(productProvider)
+ hessian.RegisterPOJO(&Product{})
+}
+
+type Product struct {
+ Id string
+ Price int
+ Quantity int
+}
+
+func (Product) JavaClassName() string {
+ return "com.ikurento.product.Product"
+}
+
+type ProductProvider struct{}
+
+func (p *ProductProvider) GetProduct(ctx context.Context, req []interface{}) (*Product, error) {
+ println("req:%#v", req)
+ rsp := Product{"A001", 100, 100}
+ println("rsp:%#v", rsp)
+ return &rsp, nil
+}
+
+func (p *ProductProvider) Reference() string {
+ return "ProductProvider"
+}
+
+func println(format string, args ...interface{}) {
+ fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...)
+}
diff --git a/golang/shop/dubbo/go-service-product/app/service.go b/golang/shop/dubbo/go-service-product/app/service.go
new file mode 100755
index 0000000..b017f6d
--- /dev/null
+++ b/golang/shop/dubbo/go-service-product/app/service.go
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/signal"
+ "syscall"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go/common/logger"
+ "github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+)
+
+var (
+ survivalTimeout = int(3e9)
+)
+
+// they are necessary:
+// export CONF_PROVIDER_FILE_PATH="xxx"
+// export APP_LOG_CONF_FILE="xxx"
+func main() {
+ config.Load()
+
+ initSignal()
+}
+
+func initSignal() {
+ signals := make(chan os.Signal, 1)
+ // It is not possible to block SIGKILL or syscall.SIGSTOP
+ signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
+ for {
+ sig := <-signals
+ logger.Infof("get signal %s", sig.String())
+ switch sig {
+ case syscall.SIGHUP:
+ // reload()
+ default:
+ time.AfterFunc(time.Duration(survivalTimeout), func() {
+ logger.Warnf("app exit now by force...")
+ os.Exit(1)
+ })
+
+ // The program exits normally or timeout forcibly exits.
+ fmt.Println("provider app exit now...")
+ return
+ }
+ }
+}
diff --git a/golang/shop/dubbo/go-service-product/app/version.go b/golang/shop/dubbo/go-service-product/app/version.go
new file mode 100755
index 0000000..22493b1
--- /dev/null
+++ b/golang/shop/dubbo/go-service-product/app/version.go
@@ -0,0 +1,22 @@
+/*
+ * 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
+
+var (
+ Version = "2.7.7"
+)
diff --git a/golang/shop/dubbo/go-service-product/profiles/log.yml b/golang/shop/dubbo/go-service-product/profiles/log.yml
new file mode 100755
index 0000000..3ed242d
--- /dev/null
+++ b/golang/shop/dubbo/go-service-product/profiles/log.yml
@@ -0,0 +1,28 @@
+
+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: "capitalColor"
+ timeEncoder: "iso8601"
+ durationEncoder: "seconds"
+ callerEncoder: "short"
+ nameEncoder: ""
+
+outputPaths:
+ - "stderr"
+errorOutputPaths:
+ - "stderr"
+initialFields:
diff --git a/golang/shop/dubbo/go-service-product/profiles/server.yml b/golang/shop/dubbo/go-service-product/profiles/server.yml
new file mode 100755
index 0000000..a2a1535
--- /dev/null
+++ b/golang/shop/dubbo/go-service-product/profiles/server.yml
@@ -0,0 +1,58 @@
+# dubbo server yaml configure file
+
+
+# application config
+application:
+ organization: "ikurento.com"
+ name: "BDTService"
+ module: "dubbogo product-info server"
+ version: "0.0.1"
+ owner: "ZX"
+ environment: "dev"
+
+registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2181"
+
+services:
+ "ProductProvider":
+ group: dg
+ version: 1.0.0
+ # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ registry: "demoZk"
+ protocol: "dubbo"
+ # 相当于dubbo.xml中的interface
+ interface: "com.ikurento.product.ProductProvider"
+ loadbalance: "random"
+ warmup: "100"
+ cluster: "failover"
+ methods:
+ - name: "GetProduct"
+ retries: 3
+ loadbalance: "random"
+
+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/golang/shop/dubbo/go-service-user/app/order.go b/golang/shop/dubbo/go-service-user/app/order.go
new file mode 100644
index 0000000..d0720c6
--- /dev/null
+++ b/golang/shop/dubbo/go-service-user/app/order.go
@@ -0,0 +1,69 @@
+/*
+ * 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 (
+ "github.com/apache/dubbo-go/config"
+)
+
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+var orderProvider = new(OrderProvider)
+
+func init() {
+ config.SetConsumerService(orderProvider)
+ hessian.RegisterPOJO(&Order{})
+ hessian.RegisterPOJO(&Product{})
+}
+
+type Order struct {
+ Id string
+ Name string
+ Price int
+ Product Product
+}
+
+func (u Order) JavaClassName() string {
+ return "com.ikurento.order.Order"
+}
+
+type Product struct {
+ Id string
+ Price int
+ Quantity int
+}
+
+func (p Product) JavaClassName() string {
+ return "com.ikurento.product.Product"
+}
+
+type OrderProvider struct {
+ GetOrder func(ctx context.Context, req []interface{}, rsp *Order) error
+}
+
+func (u *OrderProvider) Reference() string {
+ return "OrderProvider"
+}
+
+
diff --git a/golang/shop/dubbo/go-service-user/app/service.go b/golang/shop/dubbo/go-service-user/app/service.go
new file mode 100644
index 0000000..9b35739
--- /dev/null
+++ b/golang/shop/dubbo/go-service-user/app/service.go
@@ -0,0 +1,90 @@
+/*
+ * 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"
+ "fmt"
+ "os"
+ "os/signal"
+ "syscall"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go/common/logger"
+ "github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+)
+
+var (
+ survivalTimeout = int(3e9)
+)
+
+// they are necessary:
+// export CONF_CONSUMER_FILE_PATH="xxx"
+// export APP_LOG_CONF_FILE="xxx"
+func main() {
+ config.Load()
+ time.Sleep(3e9)
+
+ println("\n\n\nstart to test dubbo")
+
+ order := &Order{}
+ err := orderProvider.GetOrder(context.TODO(), []interface{}{"A001"}, order)
+ if err != nil {
+ panic(err)
+ }
+ println("response from product result: %v\n", order)
+ initSignal()
+}
+
+func initSignal() {
+ signals := make(chan os.Signal, 1)
+ // It is not possible to block SIGKILL or syscall.SIGSTOP
+ signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
+ for {
+ sig := <-signals
+ logger.Infof("get signal %s", sig.String())
+ switch sig {
+ case syscall.SIGHUP:
+ // reload()
+ default:
+ time.AfterFunc(time.Duration(survivalTimeout), func() {
+ logger.Warnf("app exit now by force...")
+ os.Exit(1)
+ })
+
+ // The program exits normally or timeout forcibly exits.
+ fmt.Println("provider app exit now...")
+ return
+ }
+ }
+}
+
+func println(format string, args ...interface{}) {
+ fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...)
+}
\ No newline at end of file
diff --git a/golang/shop/dubbo/go-service-user/app/version.go b/golang/shop/dubbo/go-service-user/app/version.go
new file mode 100755
index 0000000..22493b1
--- /dev/null
+++ b/golang/shop/dubbo/go-service-user/app/version.go
@@ -0,0 +1,22 @@
+/*
+ * 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
+
+var (
+ Version = "2.7.7"
+)
diff --git a/golang/shop/dubbo/go-service-user/profiles/client.yml b/golang/shop/dubbo/go-service-user/profiles/client.yml
new file mode 100755
index 0000000..83d22dd
--- /dev/null
+++ b/golang/shop/dubbo/go-service-user/profiles/client.yml
@@ -0,0 +1,61 @@
+# dubbo client yaml configure file
+
+
+check: true
+# client
+request_timeout: "3s"
+# connect timeout
+connect_timeout: "3s"
+
+# application config
+application:
+ organization: "ikurento.com"
+ name: "BDTService"
+ module: "dubbogo user-info client"
+ version: "0.0.1"
+ owner: "ZX"
+ environment: "dev"
+
+registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2181"
+ username: ""
+ password: ""
+
+references:
+ "OrderProvider":
+ group: dg
+ version: 1.0.0
+ # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ registry: "demoZk"
+ protocol: "dubbo"
+ interface: "com.ikurento.order.OrderProvider"
+ cluster: "failover"
+ methods:
+ - name: "GetOrder"
+ retries: 3
+
+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/golang/shop/dubbo/go-service-user/profiles/log.yml b/golang/shop/dubbo/go-service-user/profiles/log.yml
new file mode 100755
index 0000000..3ed242d
--- /dev/null
+++ b/golang/shop/dubbo/go-service-user/profiles/log.yml
@@ -0,0 +1,28 @@
+
+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: "capitalColor"
+ timeEncoder: "iso8601"
+ durationEncoder: "seconds"
+ callerEncoder: "short"
+ nameEncoder: ""
+
+outputPaths:
+ - "stderr"
+errorOutputPaths:
+ - "stderr"
+initialFields: