feat: add config center examples (#709)
* feat: add nacos as config_center example
* add nacos test
* fix: add configuration with nacos sdk
* add zookeeper
* add readme
* fix: add license
* fix: "err" shadows declaration
* fix: add zookeeper in integrate test
* fix: use raw sdk instead of config package
* fix: zk
* fix: fmt
diff --git a/config_center/nacos/README.md b/config_center/nacos/README.md
new file mode 100644
index 0000000..5fdf2f7
--- /dev/null
+++ b/config_center/nacos/README.md
@@ -0,0 +1,72 @@
+# Dubbo-go Config-Center Sample
+
+## 1. Introduction
+
+This example shows dubbo-go's dynamic configuration feature with Nacos as config-center.
+
+## 2. How to run
+
+### Configure the configuration file into nacos
+
+```yaml
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: '127.0.0.1:2181'
+ protocols:
+ triple:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreeterProvider:
+ interface: com.apache.dubbo.sample.basic.IGreeter
+```
+
+Open `https://localhost:8848/nacos/` with browser, make sure the relevant configuration is already in place in nacos.
+
+### Start an instance with nacos as the configuration center
+
+```go
+nacosOption := config_center.WithNacos()
+dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-nacos-server")
+addressOption := config_center.WithAddress("127.0.0.1:8848")
+groupOption := config_center.WithGroup("dubbo")
+ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(nacosOption, dataIdOption, addressOption, groupOption),
+)
+if err != nil {
+ panic(err)
+}
+```
+
+### Start server and register for the service
+
+```go
+srv, err := ins.NewServer()
+if err != nil {
+ panic(err)
+}
+
+if err := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}); err != nil {
+ panic(err)
+}
+
+if err := srv.Serve(); err != nil {
+ logger.Error(err)
+}
+```
+
+### Run client
+
+```shell
+$ go run ./go-client/cmd/main.go
+```
+
+### Expect output
+
+```
+Greet response: greeting:"hello world"
+```
\ No newline at end of file
diff --git a/config_center/nacos/README_zn.md b/config_center/nacos/README_zn.md
new file mode 100644
index 0000000..a6fe9e3
--- /dev/null
+++ b/config_center/nacos/README_zn.md
@@ -0,0 +1,72 @@
+# Dubbo-go Config-Center Sample
+
+## 1. 介绍
+
+本示例演示Dubbo-Go以nacos为配置中心来实现动态配置功能
+
+## 2. 如何运行
+
+### 把配置文件配置到nacos中
+
+```yaml
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: '127.0.0.1:2181'
+ protocols:
+ triple:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreeterProvider:
+ interface: com.apache.dubbo.sample.basic.IGreeter
+```
+
+使用浏览器打开`https://localhost:8848/nacos/` ,确保nacos中已有相关配置。
+
+### 以nacos作为配置中心启动一个实例
+
+```go
+nacosOption := config_center.WithNacos()
+dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-nacos-server")
+addressOption := config_center.WithAddress("127.0.0.1:8848")
+groupOption := config_center.WithGroup("dubbo")
+ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(nacosOption, dataIdOption, addressOption, groupOption),
+)
+if err != nil {
+ panic(err)
+}
+```
+
+### 启动服务端并注册服务
+
+```go
+srv, err := ins.NewServer()
+if err != nil {
+ panic(err)
+}
+
+if err := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}); err != nil {
+ panic(err)
+}
+
+if err := srv.Serve(); err != nil {
+ logger.Error(err)
+}
+```
+
+### 启动客户端
+
+```shell
+$ go run ./go-client/cmd/main.go
+```
+
+### 预期的输出
+
+```
+Greet response: greeting:"hello world"
+```
\ No newline at end of file
diff --git a/config_center/nacos/go-client/cmd/main.go b/config_center/nacos/go-client/cmd/main.go
new file mode 100644
index 0000000..7466423
--- /dev/null
+++ b/config_center/nacos/go-client/cmd/main.go
@@ -0,0 +1,110 @@
+/*
+ * 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"
+ "time"
+
+ greet "github.com/apache/dubbo-go-samples/config_center/nacos/proto"
+
+ "github.com/nacos-group/nacos-sdk-go/v2/clients"
+ "github.com/nacos-group/nacos-sdk-go/v2/common/constant"
+ "github.com/nacos-group/nacos-sdk-go/v2/vo"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/config_center"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+const configCenterNacosClientConfig = `## set in config center, group is 'dubbo', dataid is 'dubbo-go-samples-configcenter-nacos-client', namespace is default
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ references:
+ GreeterClientImpl:
+ protocol: tri
+ interface: com.apache.dubbo.sample.basic.IGreeter
+`
+
+func main() {
+ clientConfig := constant.ClientConfig{}
+ serverConfigs := []constant.ServerConfig{
+ *constant.NewServerConfig(
+ "127.0.0.1",
+ 8848,
+ constant.WithScheme("http"),
+ constant.WithContextPath("/nacos"),
+ ),
+ }
+ configClient, err := clients.NewConfigClient(
+ vo.NacosClientParam{
+ ClientConfig: &clientConfig,
+ ServerConfigs: serverConfigs,
+ },
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ success, err := configClient.PublishConfig(vo.ConfigParam{
+ DataId: "dubbo-go-samples-configcenter-nacos-client",
+ Group: "dubbo",
+ Content: configCenterNacosClientConfig,
+ })
+ if err != nil {
+ panic(err)
+ }
+ if !success {
+ return
+ }
+
+ time.Sleep(time.Second * 10)
+
+ nacosOption := config_center.WithNacos()
+ dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-nacos-client")
+ addressOption := config_center.WithAddress("127.0.0.1:8848")
+ groupOption := config_center.WithGroup("dubbo")
+ ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(nacosOption, dataIdOption, addressOption, groupOption),
+ )
+ if err != nil {
+ panic(err)
+ }
+ // configure the params that only client layer cares
+ cli, err := ins.NewClient()
+ if err != nil {
+ panic(err)
+ }
+
+ svc, err := greet.NewGreetService(cli)
+ if err != nil {
+ panic(err)
+ }
+
+ resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
+ if err != nil {
+ logger.Error(err)
+ }
+ logger.Infof("Greet response: %s", resp)
+}
diff --git a/config_center/nacos/go-server/cmd/main.go b/config_center/nacos/go-server/cmd/main.go
new file mode 100644
index 0000000..6e82e09
--- /dev/null
+++ b/config_center/nacos/go-server/cmd/main.go
@@ -0,0 +1,116 @@
+/*
+ * 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"
+ "time"
+
+ "github.com/nacos-group/nacos-sdk-go/v2/clients"
+ "github.com/nacos-group/nacos-sdk-go/v2/common/constant"
+ "github.com/nacos-group/nacos-sdk-go/v2/vo"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/config_center"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_center/nacos/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+type GreetTripleServer struct {
+}
+
+func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
+ resp := &greet.GreetResponse{Greeting: req.Name}
+ return resp, nil
+}
+
+const configCenterNacosServerConfig = `## set in config center, group is 'dubbo', dataid is 'dubbo-go-samples-configcenter-nacos-server', namespace is default
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: '127.0.0.1:2181'
+ protocols:
+ triple:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreeterProvider:
+ interface: com.apache.dubbo.sample.basic.IGreeter
+`
+
+func main() {
+ clientConfig := constant.ClientConfig{}
+ serverConfigs := []constant.ServerConfig{
+ *constant.NewServerConfig(
+ "127.0.0.1",
+ 8848,
+ constant.WithScheme("http"),
+ constant.WithContextPath("/nacos"),
+ ),
+ }
+ configClient, err := clients.NewConfigClient(
+ vo.NacosClientParam{
+ ClientConfig: &clientConfig,
+ ServerConfigs: serverConfigs,
+ },
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ success, err := configClient.PublishConfig(vo.ConfigParam{
+ DataId: "dubbo-go-samples-configcenter-nacos-server",
+ Group: "dubbo",
+ Content: configCenterNacosServerConfig,
+ })
+ if err != nil {
+ panic(err)
+ }
+ if !success {
+ return
+ }
+
+ time.Sleep(time.Second * 10)
+
+ nacosOption := config_center.WithNacos()
+ dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-nacos-server")
+ addressOption := config_center.WithAddress("127.0.0.1:8848")
+ groupOption := config_center.WithGroup("dubbo")
+ ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(nacosOption, dataIdOption, addressOption, groupOption),
+ )
+ if err != nil {
+ panic(err)
+ }
+ srv, err := ins.NewServer()
+ if err != nil {
+ panic(err)
+ }
+
+ if err = greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}); err != nil {
+ panic(err)
+ }
+
+ if err = srv.Serve(); err != nil {
+ logger.Error(err)
+ }
+}
diff --git a/config_center/nacos/proto/greet.pb.go b/config_center/nacos/proto/greet.pb.go
new file mode 100644
index 0000000..ea146c7
--- /dev/null
+++ b/config_center/nacos/proto/greet.pb.go
@@ -0,0 +1,230 @@
+/*
+ * 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.
+ */
+
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// protoc-gen-go v1.29.0
+// protoc v3.15.5
+// source: greet.proto
+
+package greet
+
+import (
+ protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ reflect "reflect"
+ sync "sync"
+)
+
+const (
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
+)
+
+type GreetRequest struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+}
+
+func (x *GreetRequest) Reset() {
+ *x = GreetRequest{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_greet_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *GreetRequest) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*GreetRequest) ProtoMessage() {}
+
+func (x *GreetRequest) ProtoReflect() protoreflect.Message {
+ mi := &file_greet_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use GreetRequest.ProtoReflect.Descriptor instead.
+func (*GreetRequest) Descriptor() ([]byte, []int) {
+ return file_greet_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *GreetRequest) GetName() string {
+ if x != nil {
+ return x.Name
+ }
+ return ""
+}
+
+type GreetResponse struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ Greeting string `protobuf:"bytes,1,opt,name=greeting,proto3" json:"greeting,omitempty"`
+}
+
+func (x *GreetResponse) Reset() {
+ *x = GreetResponse{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_greet_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *GreetResponse) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*GreetResponse) ProtoMessage() {}
+
+func (x *GreetResponse) ProtoReflect() protoreflect.Message {
+ mi := &file_greet_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use GreetResponse.ProtoReflect.Descriptor instead.
+func (*GreetResponse) Descriptor() ([]byte, []int) {
+ return file_greet_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *GreetResponse) GetGreeting() string {
+ if x != nil {
+ return x.Greeting
+ }
+ return ""
+}
+
+var File_greet_proto protoreflect.FileDescriptor
+
+var file_greet_proto_rawDesc = []byte{
+ 0x0a, 0x0b, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x67,
+ 0x72, 0x65, 0x65, 0x74, 0x22, 0x22, 0x0a, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x52, 0x65, 0x71,
+ 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
+ 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2b, 0x0a, 0x0d, 0x47, 0x72, 0x65, 0x65,
+ 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x72, 0x65,
+ 0x65, 0x74, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x72, 0x65,
+ 0x65, 0x74, 0x69, 0x6e, 0x67, 0x32, 0x44, 0x0a, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x53, 0x65,
+ 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x05, 0x47, 0x72, 0x65, 0x65, 0x74, 0x12, 0x13,
+ 0x2e, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x47, 0x72, 0x65, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75,
+ 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x47, 0x72, 0x65, 0x65,
+ 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x3b, 0x5a, 0x39, 0x67,
+ 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65,
+ 0x2f, 0x64, 0x75, 0x62, 0x62, 0x6f, 0x2d, 0x67, 0x6f, 0x2d, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65,
+ 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f,
+ 0x74, 0x6f, 0x3b, 0x67, 0x72, 0x65, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+}
+
+var (
+ file_greet_proto_rawDescOnce sync.Once
+ file_greet_proto_rawDescData = file_greet_proto_rawDesc
+)
+
+func file_greet_proto_rawDescGZIP() []byte {
+ file_greet_proto_rawDescOnce.Do(func() {
+ file_greet_proto_rawDescData = protoimpl.X.CompressGZIP(file_greet_proto_rawDescData)
+ })
+ return file_greet_proto_rawDescData
+}
+
+var file_greet_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_greet_proto_goTypes = []interface{}{
+ (*GreetRequest)(nil), // 0: greet.GreetRequest
+ (*GreetResponse)(nil), // 1: greet.GreetResponse
+}
+var file_greet_proto_depIdxs = []int32{
+ 0, // 0: greet.GreetService.Greet:input_type -> greet.GreetRequest
+ 1, // 1: greet.GreetService.Greet:output_type -> greet.GreetResponse
+ 1, // [1:2] is the sub-list for method output_type
+ 0, // [0:1] is the sub-list for method input_type
+ 0, // [0:0] is the sub-list for extension type_name
+ 0, // [0:0] is the sub-list for extension extendee
+ 0, // [0:0] is the sub-list for field type_name
+}
+
+func init() { file_greet_proto_init() }
+func file_greet_proto_init() {
+ if File_greet_proto != nil {
+ return
+ }
+ if !protoimpl.UnsafeEnabled {
+ file_greet_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*GreetRequest); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ file_greet_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*GreetResponse); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ }
+ type x struct{}
+ out := protoimpl.TypeBuilder{
+ File: protoimpl.DescBuilder{
+ GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+ RawDescriptor: file_greet_proto_rawDesc,
+ NumEnums: 0,
+ NumMessages: 2,
+ NumExtensions: 0,
+ NumServices: 1,
+ },
+ GoTypes: file_greet_proto_goTypes,
+ DependencyIndexes: file_greet_proto_depIdxs,
+ MessageInfos: file_greet_proto_msgTypes,
+ }.Build()
+ File_greet_proto = out.File
+ file_greet_proto_rawDesc = nil
+ file_greet_proto_goTypes = nil
+ file_greet_proto_depIdxs = nil
+}
diff --git a/config_center/nacos/proto/greet.proto b/config_center/nacos/proto/greet.proto
new file mode 100644
index 0000000..323eeb3
--- /dev/null
+++ b/config_center/nacos/proto/greet.proto
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+syntax = "proto3";
+
+package greet;
+
+option go_package = "github.com/apache/dubbo-go-samples/config_center/nacos/proto;greet";
+
+message GreetRequest {
+ string name = 1;
+}
+
+message GreetResponse {
+ string greeting = 1;
+}
+
+service GreetService {
+ rpc Greet(GreetRequest) returns (GreetResponse) {}
+}
\ No newline at end of file
diff --git a/config_center/nacos/proto/greet.triple.go b/config_center/nacos/proto/greet.triple.go
new file mode 100644
index 0000000..5d0c7d4
--- /dev/null
+++ b/config_center/nacos/proto/greet.triple.go
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ */
+
+// Code generated by protoc-gen-triple. DO NOT EDIT.
+//
+// Source: greet.proto
+package greet
+
+import (
+ "context"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/client"
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
+ "dubbo.apache.org/dubbo-go/v3/server"
+)
+
+// This is a compile-time assertion to ensure that this generated file and the Triple package
+// are compatible. If you get a compiler error that this constant is not defined, this code was
+// generated with a version of Triple newer than the one compiled into your binary. You can fix the
+// problem by either regenerating this code with an older version of Triple or updating the Triple
+// version compiled into your binary.
+const _ = triple_protocol.IsAtLeastVersion0_1_0
+
+const (
+ // GreetServiceName is the fully-qualified name of the GreetService service.
+ GreetServiceName = "greet.GreetService"
+)
+
+// These constants are the fully-qualified names of the RPCs defined in this package. They're
+// exposed at runtime as procedure and as the final two segments of the HTTP route.
+//
+// Note that these are different from the fully-qualified method names used by
+// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
+// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
+// period.
+const (
+ // GreetServiceGreetProcedure is the fully-qualified name of the GreetService's Greet RPC.
+ GreetServiceGreetProcedure = "/greet.GreetService/Greet"
+)
+
+var (
+ _ GreetService = (*GreetServiceImpl)(nil)
+)
+
+// GreetService is a client for the greet.GreetService service.
+type GreetService interface {
+ Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error)
+}
+
+// NewGreetService constructs a client for the greet.GreetService service.
+func NewGreetService(cli *client.Client, opts ...client.ReferenceOption) (GreetService, error) {
+ conn, err := cli.DialWithInfo("greet.GreetService", &GreetService_ClientInfo, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return &GreetServiceImpl{
+ conn: conn,
+ }, nil
+}
+
+func SetConsumerService(srv common.RPCService) {
+ dubbo.SetConsumerServiceWithInfo(srv, &GreetService_ClientInfo)
+}
+
+// GreetServiceImpl implements GreetService.
+type GreetServiceImpl struct {
+ conn *client.Connection
+}
+
+func (c *GreetServiceImpl) Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error) {
+ resp := new(GreetResponse)
+ if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "Greet", opts...); err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+var GreetService_ClientInfo = client.ClientInfo{
+ InterfaceName: "greet.GreetService",
+ MethodNames: []string{"Greet"},
+ ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {
+ dubboCli := dubboCliRaw.(*GreetServiceImpl)
+ dubboCli.conn = conn
+ },
+}
+
+// GreetServiceHandler is an implementation of the greet.GreetService service.
+type GreetServiceHandler interface {
+ Greet(context.Context, *GreetRequest) (*GreetResponse, error)
+}
+
+func RegisterGreetServiceHandler(srv *server.Server, hdlr GreetServiceHandler, opts ...server.ServiceOption) error {
+ return srv.Register(hdlr, &GreetService_ServiceInfo, opts...)
+}
+
+func SetProviderService(srv common.RPCService) {
+ dubbo.SetProviderServiceWithInfo(srv, &GreetService_ServiceInfo)
+}
+
+var GreetService_ServiceInfo = server.ServiceInfo{
+ InterfaceName: "greet.GreetService",
+ ServiceType: (*GreetServiceHandler)(nil),
+ Methods: []server.MethodInfo{
+ {
+ Name: "Greet",
+ Type: constant.CallUnary,
+ ReqInitFunc: func() interface{} {
+ return new(GreetRequest)
+ },
+ MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
+ req := args[0].(*GreetRequest)
+ res, err := handler.(GreetServiceHandler).Greet(ctx, req)
+ if err != nil {
+ return nil, err
+ }
+ return triple_protocol.NewResponse(res), nil
+ },
+ },
+ },
+}
diff --git a/config_center/zookeeper/README.md b/config_center/zookeeper/README.md
new file mode 100644
index 0000000..7a10d8e
--- /dev/null
+++ b/config_center/zookeeper/README.md
@@ -0,0 +1,72 @@
+# Dubbo-go Config-Center Sample
+
+## 1. Introduction
+
+This example shows dubbo-go's dynamic configuration feature with Zookeeper as config-center.
+
+## 2. How to run
+
+### Configure the configuration file into zookeeper
+
+```yaml
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: '127.0.0.1:2181'
+ protocols:
+ triple:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreeterProvider:
+ interface: com.apache.dubbo.sample.basic.IGreeter
+```
+
+Open the local zookeeper client to see if the configuration is successful
+
+### Start an instance with zookeeper as the configuration center
+
+```go
+zkOption := config_center.WithZookeeper()
+dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-server")
+addressOption := config_center.WithAddress("127.0.0.1:2181")
+groupOption := config_center.WithGroup("dubbogo")
+ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(zkOption, dataIdOption, addressOption, groupOption),
+)
+if err != nil {
+ panic(err)
+}
+```
+
+### Start server and register for the service
+
+```go
+srv, err := ins.NewServer()
+if err != nil {
+ panic(err)
+}
+
+if err := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}); err != nil {
+ panic(err)
+}
+
+if err := srv.Serve(); err != nil {
+ logger.Error(err)
+}
+```
+
+### Run client
+
+```shell
+$ go run ./go-client/cmd/main.go
+```
+
+### Expect output
+
+```
+Greet response: greeting:"hello world"
+```
\ No newline at end of file
diff --git a/config_center/zookeeper/README_zn.md b/config_center/zookeeper/README_zn.md
new file mode 100644
index 0000000..408b605
--- /dev/null
+++ b/config_center/zookeeper/README_zn.md
@@ -0,0 +1,72 @@
+# Dubbo-go Config-Center Sample
+
+## 1. 介绍
+
+本示例演示Dubbo-Go以ZooKeeper为配置中心来实现动态配置功能
+
+## 2. 如何运行
+
+### 把配置文件配置到zookeeper中
+
+```yaml
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: '127.0.0.1:2181'
+ protocols:
+ triple:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreeterProvider:
+ interface: com.apache.dubbo.sample.basic.IGreeter
+```
+
+打开本地ZooKeeper客户端查看配置是否成功
+
+### 以zookeeper作为配置中心启动一个实例
+
+```go
+zkOption := config_center.WithZookeeper()
+dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-server")
+addressOption := config_center.WithAddress("127.0.0.1:2181")
+groupOption := config_center.WithGroup("dubbogo")
+ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(zkOption, dataIdOption, addressOption, groupOption),
+)
+if err != nil {
+ panic(err)
+}
+```
+
+### 启动服务端并注册服务
+
+```go
+srv, err := ins.NewServer()
+if err != nil {
+ panic(err)
+}
+
+if err := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}); err != nil {
+ panic(err)
+}
+
+if err := srv.Serve(); err != nil {
+ logger.Error(err)
+}
+```
+
+### 启动客户端
+
+```shell
+$ go run ./go-client/cmd/main.go
+```
+
+### 预期的输出
+
+```
+Greet response: greeting:"hello world"
+```
\ No newline at end of file
diff --git a/config_center/zookeeper/go-client/cmd/main.go b/config_center/zookeeper/go-client/cmd/main.go
new file mode 100644
index 0000000..a3044ea
--- /dev/null
+++ b/config_center/zookeeper/go-client/cmd/main.go
@@ -0,0 +1,111 @@
+/*
+ * 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"
+ "strings"
+ "time"
+
+ perrors "github.com/pkg/errors"
+
+ "github.com/dubbogo/go-zookeeper/zk"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/config_center"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_center/zookeeper/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+const configCenterZKClientConfig = `## set in config center, group is 'dubbogo', dataid is 'dubbo-go-samples-configcenter-zookeeper-client', namespace is default
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ references:
+ GreeterClientImpl:
+ protocol: tri
+ interface: com.apache.dubbo.sample.basic.IGreeter
+`
+
+func main() {
+ c, _, err := zk.Connect([]string{"127.0.0.1:2181"}, time.Second*10)
+ if err != nil {
+ panic(err)
+ }
+
+ valueBytes := []byte(configCenterZKClientConfig)
+ path := "/dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-client"
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+ paths := strings.Split(path, "/")
+ for idx := 2; idx < len(paths); idx++ {
+ tmpPath := strings.Join(paths[:idx], "/")
+ _, err = c.Create(tmpPath, []byte{}, 0, zk.WorldACL(zk.PermAll))
+ if err != nil && err != zk.ErrNodeExists {
+ panic(err)
+ }
+ }
+
+ _, err = c.Create(path, valueBytes, 0, zk.WorldACL(zk.PermAll))
+ if err != nil {
+ if perrors.Is(err, zk.ErrNodeExists) {
+ _, stat, _ := c.Get(path)
+ _, setErr := c.Set(path, valueBytes, stat.Version)
+ if setErr != nil {
+ panic(err)
+ }
+ } else {
+ panic(err)
+ }
+ }
+
+ time.Sleep(time.Second * 10)
+
+ zkOption := config_center.WithZookeeper()
+ dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-client")
+ addressOption := config_center.WithAddress("127.0.0.1:2181")
+ groupOption := config_center.WithGroup("dubbogo")
+ ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(zkOption, dataIdOption, addressOption, groupOption),
+ )
+ if err != nil {
+ panic(err)
+ }
+ // configure the params that only client layer cares
+ cli, err := ins.NewClient()
+ if err != nil {
+ panic(err)
+ }
+
+ svc, err := greet.NewGreetService(cli)
+ if err != nil {
+ panic(err)
+ }
+
+ resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
+ if err != nil {
+ logger.Error(err)
+ }
+ logger.Infof("Greet response: %s", resp)
+}
diff --git a/config_center/zookeeper/go-server/cmd/main.go b/config_center/zookeeper/go-server/cmd/main.go
new file mode 100644
index 0000000..b082ed4
--- /dev/null
+++ b/config_center/zookeeper/go-server/cmd/main.go
@@ -0,0 +1,122 @@
+/*
+ * 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"
+ "strings"
+ "time"
+
+ perrors "github.com/pkg/errors"
+
+ "github.com/dubbogo/go-zookeeper/zk"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/config_center"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_center/zookeeper/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+type GreetTripleServer struct {
+}
+
+func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
+ resp := &greet.GreetResponse{Greeting: req.Name}
+ return resp, nil
+}
+
+const configCenterZKServerConfig = `## set in config center, group is 'dubbogo', dataid is 'dubbo-go-samples-configcenter-zookeeper-server', namespace is default
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: '127.0.0.1:2181'
+ protocols:
+ triple:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreeterProvider:
+ interface: com.apache.dubbo.sample.basic.IGreeter
+`
+
+func ensurePath(c *zk.Conn, path string, data []byte, flags int32, acl []zk.ACL) error {
+ _, err := c.Create(path, data, flags, acl)
+ return err
+}
+
+func main() {
+ c, _, err := zk.Connect([]string{"127.0.0.1:2181"}, time.Second*10)
+ if err != nil {
+ panic(err)
+ }
+
+ valueBytes := []byte(configCenterZKServerConfig)
+ path := "/dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-server"
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+ paths := strings.Split(path, "/")
+ for idx := 2; idx < len(paths); idx++ {
+ tmpPath := strings.Join(paths[:idx], "/")
+ _, err = c.Create(tmpPath, []byte{}, 0, zk.WorldACL(zk.PermAll))
+ if err != nil && err != zk.ErrNodeExists {
+ panic(err)
+ }
+ }
+
+ _, err = c.Create(path, valueBytes, 0, zk.WorldACL(zk.PermAll))
+ if err != nil {
+ if perrors.Is(err, zk.ErrNodeExists) {
+ _, stat, _ := c.Get(path)
+ _, setErr := c.Set(path, valueBytes, stat.Version)
+ if setErr != nil {
+ panic(err)
+ }
+ } else {
+ panic(err)
+ }
+ }
+ time.Sleep(time.Second * 10)
+
+ zkOption := config_center.WithZookeeper()
+ dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-server")
+ addressOption := config_center.WithAddress("127.0.0.1:2181")
+ groupOption := config_center.WithGroup("dubbogo")
+ ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(zkOption, dataIdOption, addressOption, groupOption),
+ )
+ if err != nil {
+ panic(err)
+ }
+ srv, err := ins.NewServer()
+ if err != nil {
+ panic(err)
+ }
+
+ if err = greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}); err != nil {
+ panic(err)
+ }
+
+ if err = srv.Serve(); err != nil {
+ logger.Error(err)
+ }
+}
diff --git a/config_center/zookeeper/proto/greet.pb.go b/config_center/zookeeper/proto/greet.pb.go
new file mode 100644
index 0000000..ea146c7
--- /dev/null
+++ b/config_center/zookeeper/proto/greet.pb.go
@@ -0,0 +1,230 @@
+/*
+ * 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.
+ */
+
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// protoc-gen-go v1.29.0
+// protoc v3.15.5
+// source: greet.proto
+
+package greet
+
+import (
+ protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ reflect "reflect"
+ sync "sync"
+)
+
+const (
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
+)
+
+type GreetRequest struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+}
+
+func (x *GreetRequest) Reset() {
+ *x = GreetRequest{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_greet_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *GreetRequest) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*GreetRequest) ProtoMessage() {}
+
+func (x *GreetRequest) ProtoReflect() protoreflect.Message {
+ mi := &file_greet_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use GreetRequest.ProtoReflect.Descriptor instead.
+func (*GreetRequest) Descriptor() ([]byte, []int) {
+ return file_greet_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *GreetRequest) GetName() string {
+ if x != nil {
+ return x.Name
+ }
+ return ""
+}
+
+type GreetResponse struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ Greeting string `protobuf:"bytes,1,opt,name=greeting,proto3" json:"greeting,omitempty"`
+}
+
+func (x *GreetResponse) Reset() {
+ *x = GreetResponse{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_greet_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *GreetResponse) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*GreetResponse) ProtoMessage() {}
+
+func (x *GreetResponse) ProtoReflect() protoreflect.Message {
+ mi := &file_greet_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use GreetResponse.ProtoReflect.Descriptor instead.
+func (*GreetResponse) Descriptor() ([]byte, []int) {
+ return file_greet_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *GreetResponse) GetGreeting() string {
+ if x != nil {
+ return x.Greeting
+ }
+ return ""
+}
+
+var File_greet_proto protoreflect.FileDescriptor
+
+var file_greet_proto_rawDesc = []byte{
+ 0x0a, 0x0b, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x67,
+ 0x72, 0x65, 0x65, 0x74, 0x22, 0x22, 0x0a, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x52, 0x65, 0x71,
+ 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
+ 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2b, 0x0a, 0x0d, 0x47, 0x72, 0x65, 0x65,
+ 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x72, 0x65,
+ 0x65, 0x74, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x72, 0x65,
+ 0x65, 0x74, 0x69, 0x6e, 0x67, 0x32, 0x44, 0x0a, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x53, 0x65,
+ 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x05, 0x47, 0x72, 0x65, 0x65, 0x74, 0x12, 0x13,
+ 0x2e, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x47, 0x72, 0x65, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75,
+ 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x47, 0x72, 0x65, 0x65,
+ 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x3b, 0x5a, 0x39, 0x67,
+ 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65,
+ 0x2f, 0x64, 0x75, 0x62, 0x62, 0x6f, 0x2d, 0x67, 0x6f, 0x2d, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65,
+ 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f,
+ 0x74, 0x6f, 0x3b, 0x67, 0x72, 0x65, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+}
+
+var (
+ file_greet_proto_rawDescOnce sync.Once
+ file_greet_proto_rawDescData = file_greet_proto_rawDesc
+)
+
+func file_greet_proto_rawDescGZIP() []byte {
+ file_greet_proto_rawDescOnce.Do(func() {
+ file_greet_proto_rawDescData = protoimpl.X.CompressGZIP(file_greet_proto_rawDescData)
+ })
+ return file_greet_proto_rawDescData
+}
+
+var file_greet_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_greet_proto_goTypes = []interface{}{
+ (*GreetRequest)(nil), // 0: greet.GreetRequest
+ (*GreetResponse)(nil), // 1: greet.GreetResponse
+}
+var file_greet_proto_depIdxs = []int32{
+ 0, // 0: greet.GreetService.Greet:input_type -> greet.GreetRequest
+ 1, // 1: greet.GreetService.Greet:output_type -> greet.GreetResponse
+ 1, // [1:2] is the sub-list for method output_type
+ 0, // [0:1] is the sub-list for method input_type
+ 0, // [0:0] is the sub-list for extension type_name
+ 0, // [0:0] is the sub-list for extension extendee
+ 0, // [0:0] is the sub-list for field type_name
+}
+
+func init() { file_greet_proto_init() }
+func file_greet_proto_init() {
+ if File_greet_proto != nil {
+ return
+ }
+ if !protoimpl.UnsafeEnabled {
+ file_greet_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*GreetRequest); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ file_greet_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*GreetResponse); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ }
+ type x struct{}
+ out := protoimpl.TypeBuilder{
+ File: protoimpl.DescBuilder{
+ GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+ RawDescriptor: file_greet_proto_rawDesc,
+ NumEnums: 0,
+ NumMessages: 2,
+ NumExtensions: 0,
+ NumServices: 1,
+ },
+ GoTypes: file_greet_proto_goTypes,
+ DependencyIndexes: file_greet_proto_depIdxs,
+ MessageInfos: file_greet_proto_msgTypes,
+ }.Build()
+ File_greet_proto = out.File
+ file_greet_proto_rawDesc = nil
+ file_greet_proto_goTypes = nil
+ file_greet_proto_depIdxs = nil
+}
diff --git a/config_center/zookeeper/proto/greet.proto b/config_center/zookeeper/proto/greet.proto
new file mode 100644
index 0000000..a0eef42
--- /dev/null
+++ b/config_center/zookeeper/proto/greet.proto
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+syntax = "proto3";
+
+package greet;
+
+option go_package = "github.com/apache/dubbo-go-samples/config_center/zookeeper/proto;greet";
+
+message GreetRequest {
+ string name = 1;
+}
+
+message GreetResponse {
+ string greeting = 1;
+}
+
+service GreetService {
+ rpc Greet(GreetRequest) returns (GreetResponse) {}
+}
\ No newline at end of file
diff --git a/config_center/zookeeper/proto/greet.triple.go b/config_center/zookeeper/proto/greet.triple.go
new file mode 100644
index 0000000..5d0c7d4
--- /dev/null
+++ b/config_center/zookeeper/proto/greet.triple.go
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ */
+
+// Code generated by protoc-gen-triple. DO NOT EDIT.
+//
+// Source: greet.proto
+package greet
+
+import (
+ "context"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/client"
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
+ "dubbo.apache.org/dubbo-go/v3/server"
+)
+
+// This is a compile-time assertion to ensure that this generated file and the Triple package
+// are compatible. If you get a compiler error that this constant is not defined, this code was
+// generated with a version of Triple newer than the one compiled into your binary. You can fix the
+// problem by either regenerating this code with an older version of Triple or updating the Triple
+// version compiled into your binary.
+const _ = triple_protocol.IsAtLeastVersion0_1_0
+
+const (
+ // GreetServiceName is the fully-qualified name of the GreetService service.
+ GreetServiceName = "greet.GreetService"
+)
+
+// These constants are the fully-qualified names of the RPCs defined in this package. They're
+// exposed at runtime as procedure and as the final two segments of the HTTP route.
+//
+// Note that these are different from the fully-qualified method names used by
+// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
+// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
+// period.
+const (
+ // GreetServiceGreetProcedure is the fully-qualified name of the GreetService's Greet RPC.
+ GreetServiceGreetProcedure = "/greet.GreetService/Greet"
+)
+
+var (
+ _ GreetService = (*GreetServiceImpl)(nil)
+)
+
+// GreetService is a client for the greet.GreetService service.
+type GreetService interface {
+ Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error)
+}
+
+// NewGreetService constructs a client for the greet.GreetService service.
+func NewGreetService(cli *client.Client, opts ...client.ReferenceOption) (GreetService, error) {
+ conn, err := cli.DialWithInfo("greet.GreetService", &GreetService_ClientInfo, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return &GreetServiceImpl{
+ conn: conn,
+ }, nil
+}
+
+func SetConsumerService(srv common.RPCService) {
+ dubbo.SetConsumerServiceWithInfo(srv, &GreetService_ClientInfo)
+}
+
+// GreetServiceImpl implements GreetService.
+type GreetServiceImpl struct {
+ conn *client.Connection
+}
+
+func (c *GreetServiceImpl) Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error) {
+ resp := new(GreetResponse)
+ if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "Greet", opts...); err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+var GreetService_ClientInfo = client.ClientInfo{
+ InterfaceName: "greet.GreetService",
+ MethodNames: []string{"Greet"},
+ ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {
+ dubboCli := dubboCliRaw.(*GreetServiceImpl)
+ dubboCli.conn = conn
+ },
+}
+
+// GreetServiceHandler is an implementation of the greet.GreetService service.
+type GreetServiceHandler interface {
+ Greet(context.Context, *GreetRequest) (*GreetResponse, error)
+}
+
+func RegisterGreetServiceHandler(srv *server.Server, hdlr GreetServiceHandler, opts ...server.ServiceOption) error {
+ return srv.Register(hdlr, &GreetService_ServiceInfo, opts...)
+}
+
+func SetProviderService(srv common.RPCService) {
+ dubbo.SetProviderServiceWithInfo(srv, &GreetService_ServiceInfo)
+}
+
+var GreetService_ServiceInfo = server.ServiceInfo{
+ InterfaceName: "greet.GreetService",
+ ServiceType: (*GreetServiceHandler)(nil),
+ Methods: []server.MethodInfo{
+ {
+ Name: "Greet",
+ Type: constant.CallUnary,
+ ReqInitFunc: func() interface{} {
+ return new(GreetRequest)
+ },
+ MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
+ req := args[0].(*GreetRequest)
+ res, err := handler.(GreetServiceHandler).Greet(ctx, req)
+ if err != nil {
+ return nil, err
+ }
+ return triple_protocol.NewResponse(res), nil
+ },
+ },
+ },
+}
diff --git a/go.mod b/go.mod
index 6ea26fd..a189d8e 100644
--- a/go.mod
+++ b/go.mod
@@ -5,11 +5,13 @@
github.com/SkyAPM/go2sky v1.5.0
github.com/SkyAPM/go2sky-plugins/dubbo-go v0.0.0-20220718123631-cb8f743b16cf
github.com/apache/dubbo-go-hessian2 v1.12.2
+ github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5
github.com/dubbogo/gost v1.14.0
github.com/dubbogo/grpc-go v1.42.10
github.com/dubbogo/triple v1.2.2-rc3
github.com/gogo/protobuf v1.3.2
- github.com/golang/protobuf v1.5.3
+ github.com/golang/protobuf v1.5.4
+ github.com/nacos-group/nacos-sdk-go/v2 v2.2.2
github.com/opentracing/opentracing-go v1.2.0
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5
github.com/openzipkin/zipkin-go v0.4.0
@@ -21,7 +23,7 @@
go.opentelemetry.io/otel/exporters/jaeger v1.10.0
go.opentelemetry.io/otel/sdk v1.10.0
google.golang.org/grpc v1.57.0
- google.golang.org/protobuf v1.31.0
+ google.golang.org/protobuf v1.33.0
)
go 1.15
diff --git a/go.sum b/go.sum
index 72c1901..64aa085 100644
--- a/go.sum
+++ b/go.sum
@@ -738,7 +738,6 @@
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
-github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
@@ -964,8 +963,9 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
-github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
+github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
+github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -2417,8 +2417,8 @@
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
-google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
-google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
+google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
diff --git a/integrate_test/config_center/nacos/tests/integration/config_center_nacos_test.go b/integrate_test/config_center/nacos/tests/integration/config_center_nacos_test.go
new file mode 100644
index 0000000..7985f0a
--- /dev/null
+++ b/integrate_test/config_center/nacos/tests/integration/config_center_nacos_test.go
@@ -0,0 +1,37 @@
+/*
+ * 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 integration
+
+import (
+ "context"
+ "testing"
+
+ greet "github.com/apache/dubbo-go-samples/config_center/nacos/proto"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSayHello(t *testing.T) {
+ req := &greet.GreetRequest{Name: "hello world"}
+
+ ctx := context.Background()
+
+ reply, err := greeterProvider.Greet(ctx, req)
+
+ assert.Nil(t, err)
+ assert.Equal(t, "hello world", reply.Greeting)
+}
diff --git a/integrate_test/config_center/nacos/tests/integration/main_test.go b/integrate_test/config_center/nacos/tests/integration/main_test.go
new file mode 100644
index 0000000..a4df1c5
--- /dev/null
+++ b/integrate_test/config_center/nacos/tests/integration/main_test.go
@@ -0,0 +1,106 @@
+/*
+ * 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 integration
+
+import (
+ "os"
+ "testing"
+ "time"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/config_center"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_center/nacos/proto"
+ "github.com/nacos-group/nacos-sdk-go/v2/clients"
+ "github.com/nacos-group/nacos-sdk-go/v2/common/constant"
+ "github.com/nacos-group/nacos-sdk-go/v2/vo"
+)
+
+const configCenterNacosClientConfig = `## set in config center, group is 'dubbo', dataid is 'dubbo-go-samples-configcenter-nacos-client', namespace is default
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ references:
+ GreeterClientImpl:
+ protocol: tri
+ interface: com.apache.dubbo.sample.basic.IGreeter
+`
+
+var greeterProvider greet.GreetService
+
+func TestMain(m *testing.M) {
+ clientConfig := constant.ClientConfig{}
+ serverConfigs := []constant.ServerConfig{
+ *constant.NewServerConfig(
+ "127.0.0.1",
+ 8848,
+ constant.WithScheme("http"),
+ constant.WithContextPath("/nacos"),
+ ),
+ }
+ configClient, err := clients.NewConfigClient(
+ vo.NacosClientParam{
+ ClientConfig: &clientConfig,
+ ServerConfigs: serverConfigs,
+ },
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ success, err := configClient.PublishConfig(vo.ConfigParam{
+ DataId: "dubbo-go-samples-configcenter-nacos-client",
+ Group: "dubbo",
+ Content: configCenterNacosClientConfig,
+ })
+ if err != nil {
+ panic(err)
+ }
+ if !success {
+ return
+ }
+
+ time.Sleep(time.Second * 10)
+
+ nacosOption := config_center.WithNacos()
+ dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-nacos-client")
+ addressOption := config_center.WithAddress("127.0.0.1:8848")
+ groupOption := config_center.WithGroup("dubbo")
+ ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(nacosOption, dataIdOption, addressOption, groupOption),
+ )
+ if err != nil {
+ panic(err)
+ }
+ // configure the params that only client layer cares
+ cli, err := ins.NewClient()
+ if err != nil {
+ panic(err)
+ }
+
+ greeterProvider, err = greet.NewGreetService(cli)
+ if err != nil {
+ panic(err)
+ }
+ time.Sleep(3 * time.Second)
+ os.Exit(m.Run())
+}
diff --git a/integrate_test/config_center/zookeeper/tests/integration/config_center_zookeeper_test.go b/integrate_test/config_center/zookeeper/tests/integration/config_center_zookeeper_test.go
new file mode 100644
index 0000000..ce71ff6
--- /dev/null
+++ b/integrate_test/config_center/zookeeper/tests/integration/config_center_zookeeper_test.go
@@ -0,0 +1,37 @@
+/*
+ * 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 integration
+
+import (
+ "context"
+ "testing"
+
+ greet "github.com/apache/dubbo-go-samples/config_center/zookeeper/proto"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSayHello(t *testing.T) {
+ req := &greet.GreetRequest{Name: "hello world"}
+
+ ctx := context.Background()
+
+ reply, err := greeterProvider.Greet(ctx, req)
+
+ assert.Nil(t, err)
+ assert.Equal(t, "hello world", reply.Greeting)
+}
diff --git a/integrate_test/config_center/zookeeper/tests/integration/main_test.go b/integrate_test/config_center/zookeeper/tests/integration/main_test.go
new file mode 100644
index 0000000..bf1826a
--- /dev/null
+++ b/integrate_test/config_center/zookeeper/tests/integration/main_test.go
@@ -0,0 +1,109 @@
+/*
+ * 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 integration
+
+import (
+ "os"
+ "strings"
+ "testing"
+ "time"
+
+ perrors "github.com/pkg/errors"
+
+ "github.com/dubbogo/go-zookeeper/zk"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/config_center"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_center/zookeeper/proto"
+)
+
+const configCenterZKClientConfig = `## set in config center, group is 'dubbogo', dataid is 'dubbo-go-samples-configcenter-zookeeper-client', namespace is default
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ references:
+ GreeterClientImpl:
+ protocol: tri
+ interface: com.apache.dubbo.sample.basic.IGreeter
+`
+
+var greeterProvider greet.GreetService
+
+func TestMain(m *testing.M) {
+ c, _, err := zk.Connect([]string{"127.0.0.1:2181"}, time.Second*10)
+ if err != nil {
+ panic(err)
+ }
+
+ valueBytes := []byte(configCenterZKClientConfig)
+ path := "/dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-client"
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+ paths := strings.Split(path, "/")
+ for idx := 2; idx < len(paths); idx++ {
+ tmpPath := strings.Join(paths[:idx], "/")
+ _, err = c.Create(tmpPath, []byte{}, 0, zk.WorldACL(zk.PermAll))
+ if err != nil && err != zk.ErrNodeExists {
+ panic(err)
+ }
+ }
+
+ _, err = c.Create(path, valueBytes, 0, zk.WorldACL(zk.PermAll))
+ if err != nil {
+ if perrors.Is(err, zk.ErrNodeExists) {
+ _, stat, _ := c.Get(path)
+ _, setErr := c.Set(path, valueBytes, stat.Version)
+ if setErr != nil {
+ panic(err)
+ }
+ } else {
+ panic(err)
+ }
+ }
+
+ time.Sleep(time.Second * 10)
+
+ zkOption := config_center.WithZookeeper()
+ dataIdOption := config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-client")
+ addressOption := config_center.WithAddress("127.0.0.1:2181")
+ groupOption := config_center.WithGroup("dubbogo")
+ ins, err := dubbo.NewInstance(
+ dubbo.WithConfigCenter(zkOption, dataIdOption, addressOption, groupOption),
+ )
+ if err != nil {
+ panic(err)
+ }
+ // configure the params that only client layer cares
+ cli, err := ins.NewClient()
+ if err != nil {
+ panic(err)
+ }
+
+ greeterProvider, err = greet.NewGreetService(cli)
+ if err != nil {
+ panic(err)
+ }
+ time.Sleep(3 * time.Second)
+ os.Exit(m.Run())
+}
diff --git a/integrate_test/helloworld/tests/integration/main_test.go b/integrate_test/helloworld/tests/integration/main_test.go
index 9861fbd..694092a 100644
--- a/integrate_test/helloworld/tests/integration/main_test.go
+++ b/integrate_test/helloworld/tests/integration/main_test.go
@@ -21,9 +21,8 @@
"os"
"testing"
- greet "github.com/apache/dubbo-go-samples/helloworld/proto"
-
"dubbo.apache.org/dubbo-go/v3/client"
+ greet "github.com/apache/dubbo-go-samples/helloworld/proto"
_ "dubbo.apache.org/dubbo-go/v3/imports"
)
diff --git a/start_integrate_test.sh b/start_integrate_test.sh
index a4e3753..34bff30 100755
--- a/start_integrate_test.sh
+++ b/start_integrate_test.sh
@@ -100,6 +100,10 @@
# error
array+=("error")
+#config_center
+array+=("config_center/nacos")
+array+=("config_center/zookeeper")
+
# compatibility
## registry
array+=("compatibility/registry/zookeeper")