Merge remote-tracking branch 'origin/main' into main
# Conflicts:
# multirpc/go-client/cmd/main.go
# multirpc/go-server/cmd/main.go
diff --git a/build/Makefile b/build/Makefile
index ae4884b..26b7854 100644
--- a/build/Makefile
+++ b/build/Makefile
@@ -65,6 +65,11 @@
LDFLAGS := "-s -w"
endif
+DOCKER_COMPOSE_CMD := docker-compose
+ifeq ($(shell docker compose version > /dev/null; echo $$?), 0)
+ DOCKER_COMPOSE_CMD := docker compose
+endif
+
OUT_DIR := $(BASE_DIR)/$(GOOS)_$(GOARCH)/$(BUILD_TYPE)
LOG_FILE := $(OUT_DIR)/$(PROJECT_NAME).log
@@ -106,13 +111,13 @@
.PHONY: docker-up
docker-up:
$(info > Starting dependency services with $(DOCKER_DIR)/docker-compose.yml)
- @docker-compose -f $(DOCKER_DIR)/docker-compose.yml up -d
+ @$(DOCKER_COMPOSE_CMD) -f $(DOCKER_DIR)/docker-compose.yml up -d
## docker-down: Shutdown dependency services on docker
.PHONY: docker-down
docker-down:
- $(info > Stopping dependency services with $(DOCKER_DIR)/docker-compose.ym)
- @docker-compose -f $(DOCKER_DIR)/docker-compose.yml down
+ $(info > Stopping dependency services with $(DOCKER_DIR)/docker-compose.yml)
+ @$(DOCKER_COMPOSE_CMD) -f $(DOCKER_DIR)/docker-compose.yml down
## clean: Clean up the output and the binary of the application
.PHONY: clean
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/config_yaml/README.md b/config_yaml/README.md
new file mode 100644
index 0000000..dcddd22
--- /dev/null
+++ b/config_yaml/README.md
@@ -0,0 +1,235 @@
+# Dubbo-go Config_Yaml
+
+## 1.Introduction
+
+This example demonstrates how to configure using yaml configuration files in Dubbo-go framework
+
+## 2.Run
+```txt
+.
+├── go-client
+│ ├── cmd
+│ │ └── main.go
+│ └── conf
+│ └── dubbogo.yml
+├── go-server
+│ ├── cmd
+│ │ └── main.go
+│ └── conf
+│ └── dubbogo.yml
+└─── proto
+ ├── greet.pb.go
+ ├── greet.proto
+ └── greet.triple.go
+
+```
+The service is defined using IDL (./proto/greet.proto) and utilizes the Triple protocol.
+
+### build Proto
+```bash
+cd path_to_dubbogo-sample/config_yaml/proto
+protoc --go_out=. --go-triple_out=. ./greet.proto
+```
+### Server
+```bash
+export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
+cd path_to_dubbogo-sample/config_yaml/go-server/cmd
+go run .
+```
+### Client
+```bash
+export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
+cd path_to_dubbogo-sample/config_yaml/go-client/cmd
+go run .
+```
+
+### 2.1 Client usage instructions
+
+Client-defined dubbogo.yaml
+
+```yaml
+# dubbo client yaml configure file
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ references:
+ GreetServiceImpl:
+ protocol: tri
+ interface: com.apache.dubbo.sample.Greeter
+ registry: demoZK
+ retries: 3
+ timeout: 3000
+```
+Read and load files through `dubbo.Load()`.
+
+```go
+//...
+func main() {
+ //...
+ if err := dubbo.Load(); err != nil {
+ //...
+ }
+ //...
+}
+```
+
+### 2.2 Server usage instructions
+
+Server-defined dubbogo.yaml
+
+```yaml
+# dubbo server yaml configure file
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 10s
+ address: 127.0.0.1:2181
+ protocols:
+ tripleProtocol:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreetTripleServer:
+ interface: com.apache.dubbo.sample.Greeter
+```
+
+Read and load files through `dubbo.Load()`.
+```go
+//...
+func main() {
+ //...
+ if err := dubbo.Load(); err != nil {
+ //...
+ }
+ //...
+}
+```
+## 3.Example
+
+### 3.1 Server
+
+#### IDL
+
+Source file path :dubbo-go-sample/context/proto/greet.proto
+
+```protobuf
+syntax = "proto3";
+
+package greet;
+
+option go_package = "github.com/apache/dubbo-go-samples/config_yaml/proto;greet";
+
+message GreetRequest {
+ string name = 1;
+}
+
+message GreetResponse {
+ string greeting = 1;
+}
+
+service GreetService {
+ rpc Greet(GreetRequest) returns (GreetResponse) {}
+}
+```
+
+#### Server Handler
+
+On the server side, define GreetTripleServer struct:
+```go
+type GreetServiceHandler interface {
+ Greet(context.Context, *GreetRequest) (*GreetResponse, error)
+}
+```
+Implement the GreetServiceHandler interface and register it through `greet.SetProviderService(srv common.RPCService)`
+
+Load the configuration file through `dubbo.Load()`
+
+Source file path :dubbo-go-sample/config_yaml/go-server/cmd/main.go
+
+```go
+
+package main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_yaml/proto"
+)
+
+type GreetTripleServer struct {
+}
+
+func (srv *GreetTripleServer) Greet(_ context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
+ name := req.Name
+ if name != "ConfigTest" {
+ errInfo := fmt.Sprintf("name is not right: %s", name)
+ return nil, errors.New(errInfo)
+ }
+
+ resp := &greet.GreetResponse{Greeting: req.Name + "-Success"}
+ return resp, nil
+}
+
+func main() {
+ greet.SetProviderService(&GreetTripleServer{})
+ if err := dubbo.Load(); err != nil {
+ panic(err)
+ }
+ select {}
+}
+```
+
+### 3.2 Client
+
+In the client, define greet.GreetServiceImpl instance and register it through `greet.SetConsumerService(srv common.RPCService)`:
+
+Load the configuration file through `dubbo.Load()`
+
+Source file path :dubbo-go-sample/config_yaml/go-client/cmd/main.go
+
+```go
+package main
+
+import (
+ "context"
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_yaml/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+var svc = new(greet.GreetServiceImpl)
+
+func main() {
+ greet.SetConsumerService(svc)
+ if err := dubbo.Load(); err != nil {
+ panic(err)
+ }
+ req, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "ConfigTest"})
+ if err != nil || req.Greeting != "ConfigTest-Success" {
+ panic(err)
+ }
+ logger.Info("ConfigTest successfully")
+}
+
+```
+
+### 3.3 Show
+
+Start the server first, then the client.
+If the client prints `ConfigTest Successful`, it means the configuration is loaded and the call success.
+```
+2024-03-11 15:47:29 INFO cmd/main.go:39 ConfigTest successfully
+```
+
+
diff --git a/config_yaml/README_zh.md b/config_yaml/README_zh.md
new file mode 100644
index 0000000..d87fdee
--- /dev/null
+++ b/config_yaml/README_zh.md
@@ -0,0 +1,233 @@
+# Dubbo-go Config_Yaml
+
+## 1.介绍
+
+本示例演示如何在Dubbo-go框架中使用yaml配置文件进行配置
+
+## 2.使用说明
+```txt
+.
+├── go-client
+│ ├── cmd
+│ │ └── main.go
+│ └── conf
+│ └── dubbogo.yml
+├── go-server
+│ ├── cmd
+│ │ └── main.go
+│ └── conf
+│ └── dubbogo.yml
+└─── proto
+ ├── greet.pb.go
+ ├── greet.proto
+ └── greet.triple.go
+
+```
+通过 IDL`./proto/greet.proto` 定义服务 使用triple协议
+
+
+### build Proto
+```bash
+cd path_to_dubbogo-sample/config_yaml/proto
+protoc --go_out=. --go-triple_out=. ./greet.proto
+```
+### Server
+```bash
+export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
+cd path_to_dubbogo-sample/config_yaml/go-server/cmd
+go run .
+```
+### Client
+```bash
+export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
+cd path_to_dubbogo-sample/config_yaml/go-client/cmd
+go run .
+```
+
+### 2.1客户端使用说明
+
+客户端定义的yaml文件
+```yaml
+# dubbo client yaml configure file
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ references:
+ GreetServiceImpl:
+ protocol: tri
+ interface: com.apache.dubbo.sample.Greeter
+ registry: demoZK
+ retries: 3
+ timeout: 3000
+```
+通过dubbo.Load()调用进行文件的读取以及加载
+```go
+//...
+func main() {
+ //...
+ if err := dubbo.Load(); err != nil {
+ //...
+ }
+ //...
+}
+```
+
+### 2.2服务端使用说明
+
+服务端定义的yaml文件
+```yaml
+# dubbo server yaml configure file
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 10s
+ address: 127.0.0.1:2181
+ protocols:
+ tripleProtocol:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreetTripleServer:
+ interface: com.apache.dubbo.sample.Greeter
+```
+通过dubbo.Load()调用进行文件的读取以及加载
+```go
+//...
+func main() {
+ //...
+ if err := dubbo.Load(); err != nil {
+ //...
+ }
+ //...
+}
+
+```
+## 3.案例
+
+### 3.1服务端介绍
+
+#### 服务端proto文件
+
+源文件路径:dubbo-go-sample/context/proto/greet.proto
+
+```protobuf
+syntax = "proto3";
+
+package greet;
+
+option go_package = "github.com/apache/dubbo-go-samples/config_yaml/proto;greet";
+
+message GreetRequest {
+ string name = 1;
+}
+
+message GreetResponse {
+ string greeting = 1;
+}
+
+service GreetService {
+ rpc Greet(GreetRequest) returns (GreetResponse) {}
+}
+```
+
+#### 服务端handler文件
+
+在服务端中,定义GreetTripleServer:
+```go
+type GreetServiceHandler interface {
+ Greet(context.Context, *GreetRequest) (*GreetResponse, error)
+}
+```
+实现GreetServiceHandler接口,通过`greet.SetProviderService(&GreetTripleServer{})`进行注册
+同样使用`dubbo.Load()`进行加载配置文件
+
+
+源文件路径:dubbo-go-sample/config_yaml/go-server/cmd/main.go
+
+```go
+
+package main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_yaml/proto"
+)
+
+type GreetTripleServer struct {
+}
+
+func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
+ name := req.Name
+ if name != "ConfigTest" {
+ errInfo := fmt.Sprintf("name is not right: %s", name)
+ return nil, errors.New(errInfo)
+ }
+
+ resp := &greet.GreetResponse{Greeting: req.Name + "-Success"}
+ return resp, nil
+}
+
+func main() {
+ greet.SetProviderService(&GreetTripleServer{})
+ if err := dubbo.Load(); err != nil {
+ panic(err)
+ }
+ select {}
+}
+```
+
+### 3.2客户端介绍
+
+在客户端中,定义greet.GreetServiceImpl实例,greet.SetConsumerService(svc)进行注册:
+通过 `dubbo.Load()` 进行配置文件的加载
+
+源文件路径:dubbo-go-sample/config_yaml/go-client/cmd/main.go
+
+```go
+package main
+
+import (
+ "context"
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_yaml/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+var svc = new(greet.GreetServiceImpl)
+
+func main() {
+ greet.SetConsumerService(svc)
+ if err := dubbo.Load(); err != nil {
+ panic(err)
+ }
+ req, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "ConfigTest"})
+ if err != nil || req.Greeting != "ConfigTest-Success" {
+ panic(err)
+ }
+ logger.Info("ConfigTest successfully")
+}
+
+```
+
+### 3.3案例效果
+
+先启动服务端,再启动客户端,可以观察到客户端打印了`ConfigTest successfully`配置加载以及调用成功
+
+```
+2024-03-11 15:47:29 INFO cmd/main.go:39 ConfigTest successfully
+
+```
+
+
\ No newline at end of file
diff --git a/config_yaml/go-client/cmd/main.go b/config_yaml/go-client/cmd/main.go
new file mode 100644
index 0000000..67a0018
--- /dev/null
+++ b/config_yaml/go-client/cmd/main.go
@@ -0,0 +1,41 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_yaml/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+var svc = new(greet.GreetServiceImpl)
+
+func main() {
+ greet.SetConsumerService(svc)
+ if err := dubbo.Load(); err != nil {
+ panic(err)
+ }
+ req, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "ConfigTest"})
+ if err != nil || req.Greeting != "ConfigTest-Success" {
+ panic(err)
+ }
+ logger.Info("ConfigTest successfully")
+}
diff --git a/config_yaml/go-client/conf/dubbogo.yml b/config_yaml/go-client/conf/dubbogo.yml
new file mode 100644
index 0000000..0d34a32
--- /dev/null
+++ b/config_yaml/go-client/conf/dubbogo.yml
@@ -0,0 +1,15 @@
+# dubbo client yaml configure file
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ references:
+ GreetServiceImpl:
+ protocol: tri
+ interface: com.apache.dubbo.sample.Greeter
+ registry: demoZK
+ retries: 3
+ timeout: 3000
diff --git a/config_yaml/go-server/cmd/main.go b/config_yaml/go-server/cmd/main.go
new file mode 100644
index 0000000..aee6fd5
--- /dev/null
+++ b/config_yaml/go-server/cmd/main.go
@@ -0,0 +1,50 @@
+/*
+ * 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"
+ "errors"
+ "fmt"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_yaml/proto"
+)
+
+type GreetTripleServer struct {
+}
+
+func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
+ name := req.Name
+ if name != "ConfigTest" {
+ errInfo := fmt.Sprintf("name is not right: %s", name)
+ return nil, errors.New(errInfo)
+ }
+
+ resp := &greet.GreetResponse{Greeting: req.Name + "-Success"}
+ return resp, nil
+}
+
+func main() {
+ greet.SetProviderService(&GreetTripleServer{})
+ if err := dubbo.Load(); err != nil {
+ panic(err)
+ }
+ select {}
+}
diff --git a/config_yaml/go-server/conf/dubbogo.yml b/config_yaml/go-server/conf/dubbogo.yml
new file mode 100644
index 0000000..5eec8b7
--- /dev/null
+++ b/config_yaml/go-server/conf/dubbogo.yml
@@ -0,0 +1,15 @@
+# dubbo server yaml configure file
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 10s
+ address: 127.0.0.1:2181
+ protocols:
+ tripleProtocol:
+ name: tri
+ port: 20000
+ provider:
+ services:
+ GreetTripleServer:
+ interface: com.apache.dubbo.sample.Greeter
diff --git a/config_yaml/proto/greet.pb.go b/config_yaml/proto/greet.pb.go
new file mode 100644
index 0000000..ea146c7
--- /dev/null
+++ b/config_yaml/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_yaml/proto/greet.proto b/config_yaml/proto/greet.proto
new file mode 100644
index 0000000..5320b17
--- /dev/null
+++ b/config_yaml/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_yaml/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_yaml/proto/greet.triple.go b/config_yaml/proto/greet.triple.go
new file mode 100644
index 0000000..5d0c7d4
--- /dev/null
+++ b/config_yaml/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/filter/sentinel/go-client/cmd/main.go b/filter/sentinel/go-client/cmd/main.go
new file mode 100644
index 0000000..ff28ff6
--- /dev/null
+++ b/filter/sentinel/go-client/cmd/main.go
@@ -0,0 +1,80 @@
+/*
+ * 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"
+ "dubbo.apache.org/dubbo-go/v3/client"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "github.com/alibaba/sentinel-golang/core/flow"
+ greet "github.com/apache/dubbo-go-samples/filter/proto"
+ "github.com/dubbogo/gost/log/logger"
+ "sync"
+ "sync/atomic"
+)
+
+func main() {
+ cli, err := client.NewClient(
+ client.WithClientURL("127.0.0.1:20000"),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ svc, err := greet.NewGreetService(cli, client.WithFilter(constant.SentinelConsumerFilterKey))
+ if err != nil {
+ panic(err)
+ }
+
+ // Limit the client's request to GreetService to 200QPS
+ _, err = flow.LoadRules([]*flow.Rule{
+ {
+ Resource: greet.GreetService_ServiceInfo.InterfaceName + "::",
+ TokenCalculateStrategy: flow.Direct,
+ ControlBehavior: flow.Reject,
+ Threshold: 200,
+ RelationStrategy: flow.CurrentResource,
+ StatIntervalInMs: 1000,
+ },
+ })
+ if err != nil {
+ panic(err)
+ }
+ wg := sync.WaitGroup{}
+ wg.Add(10)
+ pass := int64(0)
+ block := int64(0)
+ for i := 0; i < 10; i++ {
+ go func() {
+ for j := 0; j < 30; j++ {
+ resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
+ if err == nil {
+ atomic.AddInt64(&pass, 1)
+ logger.Info(resp.Greeting)
+ } else {
+ atomic.AddInt64(&block, 1)
+ logger.Error(err)
+ }
+ }
+ wg.Done()
+ }()
+ }
+ wg.Wait()
+ logger.Info("success:", pass, "fail:", block)
+}
diff --git a/filter/sentinel/go-server/cmd/main.go b/filter/sentinel/go-server/cmd/main.go
new file mode 100644
index 0000000..e2b83d7
--- /dev/null
+++ b/filter/sentinel/go-server/cmd/main.go
@@ -0,0 +1,73 @@
+/*
+ * 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"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ "dubbo.apache.org/dubbo-go/v3/server"
+ "github.com/alibaba/sentinel-golang/core/flow"
+ greet "github.com/apache/dubbo-go-samples/filter/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
+}
+
+func main() {
+ srv, err := server.NewServer(
+ server.WithServerProtocol(
+ protocol.WithPort(20000),
+ protocol.WithTriple(),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ if err = greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{},
+ server.WithFilter(constant.SentinelProviderFilterKey),
+ ); err != nil {
+ panic(err)
+ }
+
+ // Limit the request flow processed by GreetService to 100QPS
+ _, err = flow.LoadRules([]*flow.Rule{
+ {
+ Resource: greet.GreetService_ServiceInfo.InterfaceName + "::",
+ // MetricType: flow.QPS,
+ TokenCalculateStrategy: flow.Direct,
+ ControlBehavior: flow.Reject,
+ Threshold: 100,
+ RelationStrategy: flow.CurrentResource,
+ },
+ })
+ if err != nil {
+ panic(err)
+ }
+ if err := srv.Serve(); err != nil {
+ logger.Error(err)
+ }
+}
diff --git a/go.mod b/go.mod
index 9827ce8..dde5209 100644
--- a/go.mod
+++ b/go.mod
@@ -1,15 +1,18 @@
module github.com/apache/dubbo-go-samples
require (
- dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029
+ dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1
github.com/SkyAPM/go2sky v1.5.0
github.com/SkyAPM/go2sky-plugins/dubbo-go v0.0.0-20220718123631-cb8f743b16cf
+ github.com/alibaba/sentinel-golang v1.0.4
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 +24,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 434d366..64aa085 100644
--- a/go.sum
+++ b/go.sum
@@ -602,6 +602,8 @@
dubbo.apache.org/dubbo-go/v3 v3.0.2/go.mod h1:bODgByAf72kzG/5YIfZIODXx81pY3gaAdIQ8B4mN/Yk=
dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029 h1:+5r/DyxObRS5gUkyyojGBl/QHs8zIkmX45F0hTjciL4=
dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029/go.mod h1:Aq4YRQHYH5rF6NpeYzPfjTdwhVTOBd5BhdXXstl7EZE=
+dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1 h1:31t/KezZ7R9TYpnsQkqSa15chW3UxWEvn41erKmsvrc=
+dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1/go.mod h1:4otARIJhwkOBWdRMlOpWLCJ45LR2tu9GhtEkMU5kXyg=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@@ -736,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=
@@ -962,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=
@@ -2415,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/helloworld/README.md b/helloworld/README.md
index 9e21598..b9adb4c 100644
--- a/helloworld/README.md
+++ b/helloworld/README.md
@@ -1,4 +1,4 @@
-# Helloworld for dubbo-go
+# MultiRpc for dubbo-go
This example demonstrates the basic usage of dubbo-go as an RPC framework. Check [Quick Start][] on our official website for detailed explanation.
@@ -57,7 +57,7 @@
### Run server
```shell
-go run ./server/main.go
+go run ./go-server/cmd/main.go
```
test server work as expected:
@@ -70,7 +70,7 @@
### Run client
```shell
-go run ./client/main.go
+go run ./go-client/cmd/main.go
```
[Quick Start]: https://dubbo-next.staged.apache.org/zh-cn/overview/mannual/golang-sdk/quickstart/
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/config_yaml/tests/integration/context_test.go b/integrate_test/config_yaml/tests/integration/context_test.go
new file mode 100644
index 0000000..2be7ce3
--- /dev/null
+++ b/integrate_test/config_yaml/tests/integration/context_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_yaml/proto"
+ "github.com/dubbogo/gost/log/logger"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSayHello(t *testing.T) {
+ req := &greet.GreetRequest{Name: "ConfigTest"}
+
+ reply, err := greeterProvider.Greet(context.Background(), req)
+
+ assert.Nil(t, err)
+ logger.Debug(reply)
+ assert.Equal(t, "ConfigTest-Success", reply.Greeting)
+}
diff --git a/integrate_test/config_yaml/tests/integration/main_test.go b/integrate_test/config_yaml/tests/integration/main_test.go
new file mode 100644
index 0000000..5e241e5
--- /dev/null
+++ b/integrate_test/config_yaml/tests/integration/main_test.go
@@ -0,0 +1,46 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3/client"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/config_yaml/proto"
+)
+
+var greeterProvider greet.GreetService
+
+func TestMain(m *testing.M) {
+ cli, err := client.NewClient(
+ client.WithClientURL("tri://127.0.0.1:20000"),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ greeterProvider, err = greet.NewGreetService(cli)
+
+ if err != nil {
+ panic(err)
+ }
+
+ 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/integrate_test/retry/tests/integration/mian_test.go b/integrate_test/retry/tests/integration/main_test.go
similarity index 100%
rename from integrate_test/retry/tests/integration/mian_test.go
rename to integrate_test/retry/tests/integration/main_test.go
diff --git a/integrate_test/rpc/triple/pb-json/tests/integration/main_test.go b/integrate_test/rpc/triple/pb-json/tests/integration/main_test.go
new file mode 100644
index 0000000..e62e95b
--- /dev/null
+++ b/integrate_test/rpc/triple/pb-json/tests/integration/main_test.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 integration
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "os"
+ "testing"
+
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb-json/proto"
+
+ "dubbo.apache.org/dubbo-go/v3/client"
+
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+)
+
+var greeterProvider greet.GreetService
+
+func TestMain(m *testing.M) {
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_rpc_triple_json_client"),
+ )
+ if err != nil {
+ panic(err)
+ }
+ cli, err := ins.NewClient(
+ client.WithClientURL("127.0.0.1:20000"),
+ client.WithClientProtocolTriple(),
+ client.WithClientSerialization(constant.JSONSerialization),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ greeterProvider, err = greet.NewGreetService(cli)
+
+ if err != nil {
+ panic(err)
+ }
+
+ os.Exit(m.Run())
+}
diff --git a/integrate_test/rpc/triple/pb-json/tests/integration/pb-jsonprovider_test.go b/integrate_test/rpc/triple/pb-json/tests/integration/pb-jsonprovider_test.go
new file mode 100644
index 0000000..157ff7e
--- /dev/null
+++ b/integrate_test/rpc/triple/pb-json/tests/integration/pb-jsonprovider_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/rpc/triple/pb-json/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/rpc/triple/pb/tests/integration/main_test.go b/integrate_test/rpc/triple/pb/tests/integration/main_test.go
new file mode 100644
index 0000000..d548dd3
--- /dev/null
+++ b/integrate_test/rpc/triple/pb/tests/integration/main_test.go
@@ -0,0 +1,46 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3/client"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb/proto"
+)
+
+var greetService greet.GreetService
+
+func TestMain(m *testing.M) {
+ cli, err := client.NewClient(
+ client.WithClientURL("127.0.0.1:20000"),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ greetService, err = greet.NewGreetService(cli)
+
+ if err != nil {
+ panic(err)
+ }
+
+ os.Exit(m.Run())
+}
diff --git a/integrate_test/rpc/triple/pb/tests/integration/pbprovider_test.go b/integrate_test/rpc/triple/pb/tests/integration/pbprovider_test.go
new file mode 100644
index 0000000..4cb0244
--- /dev/null
+++ b/integrate_test/rpc/triple/pb/tests/integration/pbprovider_test.go
@@ -0,0 +1,39 @@
+/*
+ * 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/rpc/triple/pb/proto"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestConnectWithGRPC(t *testing.T) {
+ req := &greet.GreetRequest{
+ Name: "dubbo:pb",
+ }
+
+ ctx := context.Background()
+
+ reply, err := greetService.Greet(ctx, req)
+
+ assert.Nil(t, err)
+ assert.Equal(t, "dubbo:pb", reply.Greeting)
+}
diff --git a/integrate_test/rpc/triple/pb2/tests/integration/main_test.go b/integrate_test/rpc/triple/pb2/tests/integration/main_test.go
new file mode 100644
index 0000000..e5566e7
--- /dev/null
+++ b/integrate_test/rpc/triple/pb2/tests/integration/main_test.go
@@ -0,0 +1,46 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3/client"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb2/proto"
+)
+
+var greetService greet.GreetService
+
+func TestMain(m *testing.M) {
+ cli, err := client.NewClient(
+ client.WithClientURL("127.0.0.1:20000"),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ greetService, err = greet.NewGreetService(cli)
+
+ if err != nil {
+ panic(err)
+ }
+
+ os.Exit(m.Run())
+}
diff --git a/integrate_test/rpc/triple/pb2/tests/integration/pb2provider_test.go b/integrate_test/rpc/triple/pb2/tests/integration/pb2provider_test.go
new file mode 100644
index 0000000..b33c050
--- /dev/null
+++ b/integrate_test/rpc/triple/pb2/tests/integration/pb2provider_test.go
@@ -0,0 +1,40 @@
+/*
+ * 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/rpc/triple/pb2/proto"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestConnectWithGRPC(t *testing.T) {
+ name_str := "dubbo:pb"
+ req := &greet.GreetRequest{
+ Name: &name_str,
+ }
+
+ ctx := context.Background()
+
+ reply, err := greetService.Greet(ctx, req)
+
+ assert.Nil(t, err)
+ assert.Equal(t, name_str, *reply.Greeting)
+}
diff --git a/metrics/Deployment.yml b/metrics/Deployment.yml
new file mode 100644
index 0000000..76217c5
--- /dev/null
+++ b/metrics/Deployment.yml
@@ -0,0 +1,131 @@
+# 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.
+
+#zookeeper
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: dubbo-system
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: zookeeper
+ namespace: dubbo-system
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: zookeeper
+ template:
+ metadata:
+ labels:
+ app: zookeeper
+ spec:
+ containers:
+ - name: zookeeper
+ image: zookeeper:latest
+ imagePullPolicy: Always
+ ports:
+ - containerPort: 2181
+ name: rpc
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: zookeeper
+ namespace: dubbo-system
+spec:
+ type: ClusterIP
+ sessionAffinity: None
+ selector:
+ app: zookeeper
+ ports:
+ - port: 2181
+ name: rpc
+ targetPort: 2181
+---
+
+#provider
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: dubbo-app
+ namespace: dubbo-system
+ labels:
+ app: dubbo-app
+ app-type: dubbo
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: dubbo-app
+ app-type: dubbo
+ template:
+ metadata:
+ name: dubbo-app
+ labels:
+ app: dubbo-app
+ app-type: dubbo
+ spec:
+ containers:
+ - name: dubbo-app
+ image: metrics-app:latest # change to your docker image
+ env:
+ - name: ZOOKEEPER_ADDRESS
+ value: zookeeper.dubbo-system.svc.cluster.local
+ imagePullPolicy: Never
+ ports:
+ - name: dubbo
+ containerPort: 20000
+ protocol: TCP
+ - name: metrics
+ containerPort: 9099
+ protocol: TCP
+---
+#consumer
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: dubbo-client
+ namespace: dubbo-system
+ labels:
+ app: dubbo-client
+ app-type: dubbo
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: dubbo-client
+ app-type: dubbo
+ template:
+ metadata:
+ name: dubbo-client
+ labels:
+ app: dubbo-client
+ app-type: dubbo
+ spec:
+ containers:
+ - name: dubbo-client
+ image: metrics-client:latest # change to your docker image
+ env:
+ - name: ZOOKEEPER_ADDRESS
+ value: zookeeper.dubbo-system.svc.cluster.local
+ imagePullPolicy: Never
+ ports:
+ - name: metrics
+ containerPort: 9097
+ protocol: TCP
\ No newline at end of file
diff --git a/metrics/README.md b/metrics/README.md
new file mode 100644
index 0000000..54975ff
--- /dev/null
+++ b/metrics/README.md
@@ -0,0 +1,139 @@
+# metrics for dubbo-go
+
+This example demonstrates the metrics usage of dubbo-go as an RPC framework. Check [Quick Start][] on our official website for detailed explanation.
+
+## Contents
+
+- server/main.go - is the main definition of the service, handler and rpc server
+- client/main.go - is the rpc client
+- proto - contains the protobuf definition of the API
+
+## How to run
+
+### Run server
+```shell
+go run ./go-server/cmd/main.go
+```
+
+test server work as expected:
+```shell
+curl \
+ --header "Content-Type: application/json" \
+ --data '{"name": "Dubbo"}' \
+ http://localhost:20000/greet.GreetService/Greet
+```
+
+### Run client
+```shell
+go run ./go-client/cmd/main.go
+```
+
+## deploy to local
+install prometheus and open prometheus config file `prometheus.yml`, write the config like this
+
+```yaml
+global:
+ evaluation_interval: 15s
+ scrape_interval: 15s
+scrape_configs:
+- job_name: dubbo-provider
+ scrape_interval: 15s
+ scrape_timeout: 5s
+ metrics_path: /prometheus
+ static_configs:
+ - targets: ['localhost:9099']
+- job_name: dubbo-consumer
+ scrape_interval: 15s
+ scrape_timeout: 5s
+ metrics_path: /prometheus
+ static_configs:
+ - targets: ['localhost:9097']
+```
+
+install grafana and open grafana web page like `localhost:3000`
+
+open: 【Home / Connections / Data sources】
+
+click 【Add new data source】
+
+select Prometheus
+
+enter 【Prometheus server URL】 like `http://localhost:9090` and click 【Save & test】
+
+![datasource.png](./assert/datasource.png)
+
+open 【Home / Dashboards 】click 【New】【import】and enter 19294 click Load
+
+![import](./assert/import.png)
+
+if your grafana can't access internet you can open `https://grafana.com/grafana/dashboards/19294-dubbo-observability/` and click 【Download JSON】
+
+paste the JSON
+
+![json.png](./assert/import-json.png)
+
+![datasource.png](./assert/import-datasource.png)
+
+click 【Import】button and you will see the Dubbo Observability dashboard,enjoy it
+
+![databoard](./assert/dashboard.png)
+
+## Deploy to Kubernetes
+
+#### kube-prometheus
+
+install prometheus in k8s [kube-prometheus](https://github.com/prometheus-operator/kube-prometheus)
+
+Set `prometheus-service.yaml` type to NodePort
+
+1. add `dubboPodMoitor.yaml` to `kube-prometheus` `manifests` dir, The content is as follows
+ ```yaml
+apiVersion: monitoring.coreos.com/v1
+kind: PodMonitor
+metadata:
+ name: podmonitor
+ labels:
+ app: podmonitor
+ namespace: monitoring
+spec:
+ namespaceSelector:
+ matchNames:
+ - dubbo-system
+ selector:
+ matchLabels:
+ app-type: dubbo
+ podMetricsEndpoints:
+ - port: metrics # ref to dubbo-app port name metrics
+ path: /prometheus
+---
+# rbac
+apiVersion: rbac.authorization.k8s.io/v1
+kind: Role
+metadata:
+ namespace: dubbo-system
+ name: pod-reader
+rules:
+ - apiGroups: [""]
+ resources: ["pods"]
+ verbs: ["get", "list", "watch"]
+
+---
+# rbac
+apiVersion: rbac.authorization.k8s.io/v1
+kind: RoleBinding
+metadata:
+ name: pod-reader-binding
+ namespace: dubbo-system
+roleRef:
+ apiGroup: rbac.authorization.k8s.io
+ kind: Role
+ name: pod-reader
+subjects:
+ - kind: ServiceAccount
+ name: prometheus-k8s
+ namespace: monitoring
+```
+2. `kubectl apply -f Deployment.yaml`
+3. open prometheus web page such as http://localhost:9090/targets
+ ![podmonitor.png](./assert/podmonitor.png)
+
diff --git a/metrics/assert/dashboard.png b/metrics/assert/dashboard.png
new file mode 100644
index 0000000..4cebf52
--- /dev/null
+++ b/metrics/assert/dashboard.png
Binary files differ
diff --git a/metrics/assert/datasource.png b/metrics/assert/datasource.png
new file mode 100644
index 0000000..d19e74b
--- /dev/null
+++ b/metrics/assert/datasource.png
Binary files differ
diff --git a/metrics/assert/import-datasource.png b/metrics/assert/import-datasource.png
new file mode 100644
index 0000000..333d6b9
--- /dev/null
+++ b/metrics/assert/import-datasource.png
Binary files differ
diff --git a/metrics/assert/import-json.png b/metrics/assert/import-json.png
new file mode 100644
index 0000000..025eb68
--- /dev/null
+++ b/metrics/assert/import-json.png
Binary files differ
diff --git a/metrics/assert/import.png b/metrics/assert/import.png
new file mode 100644
index 0000000..41d3913
--- /dev/null
+++ b/metrics/assert/import.png
Binary files differ
diff --git a/metrics/assert/podmonitor.png b/metrics/assert/podmonitor.png
new file mode 100644
index 0000000..f1f7ec9
--- /dev/null
+++ b/metrics/assert/podmonitor.png
Binary files differ
diff --git a/metrics/go-client/Dockerfile b/metrics/go-client/Dockerfile
new file mode 100644
index 0000000..c419d34
--- /dev/null
+++ b/metrics/go-client/Dockerfile
@@ -0,0 +1,23 @@
+# 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.
+
+FROM ubuntu:latest
+
+WORKDIR /app
+
+COPY ./metricsClient .
+
+CMD ["./metricsClient"]
\ No newline at end of file
diff --git a/metrics/go-client/build.sh b/metrics/go-client/build.sh
new file mode 100644
index 0000000..f0be09a
--- /dev/null
+++ b/metrics/go-client/build.sh
@@ -0,0 +1,20 @@
+#
+# 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.
+
+# if run on linux server use this
+#GOOS=linux GOARCH=amd64
+go build -o metricsClient cmd/main.go
+docker build . -t metrics-client:latest
\ No newline at end of file
diff --git a/metrics/go-client/cmd/main.go b/metrics/go-client/cmd/main.go
index 76f3df3..a495ae4 100644
--- a/metrics/go-client/cmd/main.go
+++ b/metrics/go-client/cmd/main.go
@@ -19,19 +19,27 @@
import (
"context"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+ "github.com/dubbogo/gost/log/logger"
+ "os"
"time"
"dubbo.apache.org/dubbo-go/v3"
"dubbo.apache.org/dubbo-go/v3/metrics"
- "dubbo.apache.org/dubbo-go/v3/client"
_ "dubbo.apache.org/dubbo-go/v3/imports"
greet "github.com/apache/dubbo-go-samples/helloworld/proto"
- "github.com/dubbogo/gost/log/logger"
)
func main() {
+ zookeeper := os.Getenv("ZOOKEEPER_ADDRESS")
+ if zookeeper == "" {
+ zookeeper = "localhost"
+ }
ins, err := dubbo.NewInstance(
+ dubbo.WithRegistry(
+ registry.WithAddress("zookeeper://"+zookeeper+":2181"),
+ ),
dubbo.WithMetrics(
metrics.WithEnabled(),
metrics.WithPrometheus(), // set prometheus metric
@@ -57,9 +65,7 @@
if err != nil {
panic(err)
}
- cli, err := ins.NewClient(
- client.WithClientURL("127.0.0.1:20000"),
- )
+ cli, err := ins.NewClient()
if err != nil {
panic(err)
}
@@ -69,10 +75,13 @@
panic(err)
}
- resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
- if err != nil {
- logger.Error(err)
+ for true {
+ resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
+ if err != nil {
+ logger.Error(err)
+ } else {
+ logger.Infof("Greet response: %s", resp.Greeting)
+ }
+ time.Sleep(100 * time.Millisecond)
}
- logger.Infof("Greet response: %s", resp.Greeting)
- select {}
}
diff --git a/metrics/go-server/Dockerfile b/metrics/go-server/Dockerfile
new file mode 100644
index 0000000..c005ec7
--- /dev/null
+++ b/metrics/go-server/Dockerfile
@@ -0,0 +1,23 @@
+# 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.
+
+FROM ubuntu:latest
+
+WORKDIR /app
+
+COPY ./metricsApp .
+
+CMD ["./metricsApp"]
\ No newline at end of file
diff --git a/metrics/go-server/build.sh b/metrics/go-server/build.sh
new file mode 100644
index 0000000..8b6c7bc
--- /dev/null
+++ b/metrics/go-server/build.sh
@@ -0,0 +1,20 @@
+#
+# 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.
+
+# if run on linux server use this
+#GOOS=linux GOARCH=arm64
+go build -o metricsApp cmd/main.go
+docker build . -t metrics-app:latest
\ No newline at end of file
diff --git a/metrics/go-server/cmd/main.go b/metrics/go-server/cmd/main.go
index 2057bb5..3793c14 100644
--- a/metrics/go-server/cmd/main.go
+++ b/metrics/go-server/cmd/main.go
@@ -19,6 +19,10 @@
import (
"context"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+ "github.com/pkg/errors"
+ "math/rand"
+ "os"
"time"
"dubbo.apache.org/dubbo-go/v3"
@@ -36,20 +40,32 @@
func (srv *GreetTripleServer) Greet(_ context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
resp := &greet.GreetResponse{Greeting: req.Name}
+ rand.Seed(time.Now().UnixNano())
+ if rand.Intn(101) > 99 { // mock error here
+ return nil, errors.New("random error")
+ }
+ time.Sleep(10 * time.Millisecond) // mock business delay
return resp, nil
}
func main() {
+ zookeeper := os.Getenv("ZOOKEEPER_ADDRESS")
+ if zookeeper == "" {
+ zookeeper = "localhost"
+ }
ins, err := dubbo.NewInstance(
+ dubbo.WithRegistry(
+ registry.WithAddress("zookeeper://"+zookeeper+":2181"),
+ ),
dubbo.WithMetrics(
- metrics.WithEnabled(),
- metrics.WithPrometheus(), // set prometheus metric
- metrics.WithPrometheusExporterEnabled(), // enable prometheus exporter
- metrics.WithPort(9099), // prometheus http exporter listen at 9099
- metrics.WithPath("/prometheus"), // prometheus http exporter url path
- metrics.WithMetadataEnabled(), // enable metadata center metrics
- metrics.WithRegistryEnabled(), // enable registry metrics
- metrics.WithConfigCenterEnabled(), // enable config center metrics
+ metrics.WithEnabled(), // default false
+ metrics.WithPrometheus(), // set prometheus metric, default prometheus
+ metrics.WithPrometheusExporterEnabled(), // enable prometheus exporter default false
+ metrics.WithPort(9099), // prometheus http exporter listen at 9099,default 9090
+ metrics.WithPath("/prometheus"), // prometheus http exporter url path, default /metrics
+ metrics.WithMetadataEnabled(), // enable metadata center metrics, default true
+ metrics.WithRegistryEnabled(), // enable registry metrics, default true
+ metrics.WithConfigCenterEnabled(), // enable config center metrics, default true
metrics.WithPrometheusPushgatewayEnabled(), // enable prometheus pushgateway
metrics.WithPrometheusGatewayUsername("username"),
@@ -58,7 +74,7 @@
metrics.WithPrometheusGatewayInterval(time.Second*10),
metrics.WithPrometheusGatewayJob("push"), // set a metric job label, job=push to metric
- metrics.WithAggregationEnabled(), // enable rpc metrics aggregations,Most of the time there is no need to turn it on
+ metrics.WithAggregationEnabled(), // enable rpc metrics aggregations,Most of the time there is no need to turn it on, default false
metrics.WithAggregationTimeWindowSeconds(30),
metrics.WithAggregationBucketNum(10), // agg bucket num
),
diff --git a/multirpc/go-client/cmd/main.go b/multirpc/go-client/cmd/main.go
index d3fd3df..aa591cd 100644
--- a/multirpc/go-client/cmd/main.go
+++ b/multirpc/go-client/cmd/main.go
@@ -29,7 +29,7 @@
func main() {
ins, err := dubbo.NewInstance(
- dubbo.WithName("dubbo_multirpc_triple_client"),
+ dubbo.WithName("dubbo_multirpc_client"),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),
@@ -38,44 +38,28 @@
if err != nil {
panic(err)
}
- //test triple
- cliTriple, err := ins.NewClient(
- client.WithClientProtocolTriple(),
- )
- if err != nil {
- panic(err)
- }
- svc, err := greet.NewGreetService(cliTriple)
+ cli, err := ins.NewClient()
if err != nil {
panic(err)
}
- resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
+ //Triple
+ client.WithProtocolTriple()
+ svc, err := greet.NewGreetService(cli)
+ if err != nil {
+ panic(err)
+ }
+
+ respTriple, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
if err != nil {
logger.Error(err)
}
- logger.Infof("Greet multirpc response: %s", resp)
+ logger.Infof("Greet triple response: %s", respTriple.Greeting)
- //test dubbo
- ins_dubbo, err := dubbo.NewInstance(
- dubbo.WithName("dubbo_multirpc_dubbo_client"),
- dubbo.WithRegistry(
- registry.WithZookeeper(),
- registry.WithAddress("127.0.0.1:2181"),
- ),
- )
- if err != nil {
- panic(err)
- }
- cli_dubbo, err := ins_dubbo.NewClient(
- client.WithClientProtocolDubbo(),
- client.WithClientSerialization(constant.Hessian2Serialization),
- )
- if err != nil {
- panic(err)
- }
-
- connDubbo, err := cli_dubbo.Dial("GreetProvider")
+ //Duboo
+ client.WithProtocolDubbo()
+ client.WithClientSerialization(constant.Hessian2Serialization)
+ connDubbo, err := cli.Dial("GreetProvider")
if err != nil {
panic(err)
}
@@ -84,28 +68,12 @@
logger.Errorf("GreetProvider.Greet err: %s", err)
return
}
- logger.Infof("Get Response: %s", respDubbo)
+ logger.Infof("Get dubbo Response: %s", respDubbo)
- //test json rpc
- insJsonRpc, err := dubbo.NewInstance(
- dubbo.WithName("dubbo_multirpc_jsonrpc_client"),
- dubbo.WithRegistry(
- registry.WithZookeeper(),
- registry.WithAddress("127.0.0.1:2181"),
- ),
- )
- if err != nil {
- panic(err)
- }
- cliJsonRpc, err := insJsonRpc.NewClient(
- client.WithClientProtocolJsonRPC(),
- client.WithClientSerialization(constant.Hessian2Serialization),
- )
- if err != nil {
- panic(err)
- }
-
- connJsonRpc, err := cliJsonRpc.Dial("GreetProvider")
+ //JsonRpc
+ client.WithProtocolJsonRPC()
+ client.WithClientSerialization(constant.Hessian2Serialization)
+ connJsonRpc, err := cli.Dial("GreetProvider")
if err != nil {
panic(err)
}
@@ -114,6 +82,5 @@
logger.Errorf("GreetProvider.Greet err: %s", err)
return
}
- logger.Infof("Get Response: %s", respJsonRpc)
-
+ logger.Infof("Get jsonrpc Response: %s", respJsonRpc)
}
diff --git a/multirpc/go-server/cmd/main.go b/multirpc/go-server/cmd/main.go
index 5696dad..d53df1c 100644
--- a/multirpc/go-server/cmd/main.go
+++ b/multirpc/go-server/cmd/main.go
@@ -14,12 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package main
import (
"context"
-
"dubbo.apache.org/dubbo-go/v3"
_ "dubbo.apache.org/dubbo-go/v3/imports"
"dubbo.apache.org/dubbo-go/v3/protocol"
@@ -37,31 +35,115 @@
return resp, nil
}
+type GreetProvider struct {
+}
+
+func (*GreetProvider) Greet(req string, req1 string, req2 string) (string, error) {
+ return req + req1 + req2, nil
+}
+
func main() {
+ //triple
ins, err := dubbo.NewInstance(
- dubbo.WithName("dubbo_multirpc_server"),
+ dubbo.WithName("dubbo_multirpc_triple_server"),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),
),
+ //dubbo.WithProtocol(protocol.WithDubbo()),
+ dubbo.WithProtocol(protocol.WithTriple()),
+ //dubbo.WithProtocol(protocol.WithJSONRPC()),
)
if err != nil {
panic(err)
}
+ //var protocols []string
+ //protocols = append(protocols, "tri", "dubbo", "jsonrpc")
srv, err := ins.NewServer(
server.WithServerProtocol(
- protocol.WithDubbo(),
- protocol.WithJSONRPC(),
protocol.WithTriple(),
protocol.WithPort(20000),
),
+ //server.WithServerProtocolIDs(protocols),
)
if err != nil {
panic(err)
}
+ // 利用生成代码注册业务逻辑(GreetTripleServer)
+ // service配置,可以在此处覆盖server注入的默认配置
+ // 若观察RegisterGreetServiceHandler的代码,会发现本质上是调用Server.Register
if err := greet.RegisterGreetServiceHandler(srv, &GreetMultiRPCServer{}); err != nil {
panic(err)
}
+ // 运行
+ if err := srv.Serve(); err != nil {
+ logger.Error(err)
+ }
+
+ //dubbo
+ insDubbo, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_multirpc_dubbo_server"),
+ dubbo.WithRegistry(
+ registry.WithZookeeper(),
+ registry.WithAddress("127.0.0.1:2181"),
+ ),
+ dubbo.WithProtocol(protocol.WithDubbo()),
+ //dubbo.WithProtocol(protocol.WithTriple()),
+ //dubbo.WithProtocol(protocol.WithJSONRPC()),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ srvDubbo, err := insDubbo.NewServer(
+ server.WithServerProtocol(
+ protocol.WithDubbo(),
+ protocol.WithPort(20000),
+ ),
+ //server.WithServerProtocolIDs(protocols),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ if err := srvDubbo.Register(&GreetProvider{}, nil, server.WithInterface("GreetProvider")); err != nil {
+ panic(err)
+ }
+ // 运行
+ if err := srv.Serve(); err != nil {
+ logger.Error(err)
+ }
+
+ //JsonRpc
+ insJsonRpc, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_multirpc_jsonrpc_server"),
+ dubbo.WithRegistry(
+ registry.WithZookeeper(),
+ registry.WithAddress("127.0.0.1:2181"),
+ ),
+ dubbo.WithProtocol(protocol.WithJSONRPC()),
+ //dubbo.WithProtocol(protocol.WithTriple()),
+ //dubbo.WithProtocol(protocol.WithJSONRPC()),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ srvJsonRpc, err := insJsonRpc.NewServer(
+ server.WithServerProtocol(
+ protocol.WithJSONRPC(),
+ protocol.WithPort(20000),
+ ),
+ //server.WithServerProtocolIDs(protocols),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ if err := srvJsonRpc.Register(&GreetProvider{}, nil, server.WithInterface("GreetProvider")); err != nil {
+ panic(err)
+ }
+ // 运行
if err := srv.Serve(); err != nil {
logger.Error(err)
}
diff --git a/rpc/triple/pb-json/go-client/cmd/main.go b/rpc/triple/pb-json/go-client/cmd/main.go
new file mode 100644
index 0000000..a0f982d
--- /dev/null
+++ b/rpc/triple/pb-json/go-client/cmd/main.go
@@ -0,0 +1,56 @@
+/*
+ * 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"
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/client"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb-json/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+func main() {
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_rpc_triple_json_client"),
+ )
+ if err != nil {
+ panic(err)
+ }
+ cli, err := ins.NewClient(
+ client.WithClientURL("127.0.0.1:20000"),
+ client.WithClientProtocolTriple(),
+ //The default serialization format is protobuf.
+ client.WithClientSerialization(constant.JSONSerialization),
+ )
+ 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/rpc/triple/pb-json/go-server/cmd/main.go b/rpc/triple/pb-json/go-server/cmd/main.go
new file mode 100644
index 0000000..b9f746c
--- /dev/null
+++ b/rpc/triple/pb-json/go-server/cmd/main.go
@@ -0,0 +1,63 @@
+/*
+ * 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"
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ "dubbo.apache.org/dubbo-go/v3/server"
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb-json/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
+}
+
+func main() {
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_rpc_triple_json_server"),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ srv, err := ins.NewServer(
+ server.WithServerProtocol(
+ protocol.WithTriple(),
+ protocol.WithPort(20000),
+ ),
+ )
+ 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/rpc/triple/pb-json/proto/greet.pb.go b/rpc/triple/pb-json/proto/greet.pb.go
new file mode 100644
index 0000000..41ca482
--- /dev/null
+++ b/rpc/triple/pb-json/proto/greet.pb.go
@@ -0,0 +1,231 @@
+/*
+ * 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.31.0
+// protoc v4.23.4
+// 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" pb-pb-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" pb-pb-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, 0x40, 0x5a, 0x3e, 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, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x2f, 0x6a, 0x73, 0x6f,
+ 0x6e, 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/rpc/triple/pb-json/proto/greet.proto b/rpc/triple/pb-json/proto/greet.proto
new file mode 100644
index 0000000..28fd8aa
--- /dev/null
+++ b/rpc/triple/pb-json/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/rpc/triple/pb-json/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/rpc/triple/pb-json/proto/greet.triple.go b/rpc/triple/pb-json/proto/greet.triple.go
new file mode 100644
index 0000000..c40d881
--- /dev/null
+++ b/rpc/triple/pb-json/proto/greet.triple.go
@@ -0,0 +1,136 @@
+/*
+ * 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"
+ "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/rpc/triple/pb/go-client/cmd/main.go b/rpc/triple/pb/go-client/cmd/main.go
new file mode 100644
index 0000000..1b9070d
--- /dev/null
+++ b/rpc/triple/pb/go-client/cmd/main.go
@@ -0,0 +1,63 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/client"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+func main() {
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_rpc_triple_pb_client"),
+ dubbo.WithRegistry(
+ registry.WithZookeeper(),
+ registry.WithAddress("127.0.0.1:2181"),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ cli, err := ins.NewClient(
+ client.WithClientProtocolTriple(),
+ client.WithClientSerialization(constant.ProtobufSerialization),
+ )
+
+ 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/rpc/triple/pb/go-server/cmd/main.go b/rpc/triple/pb/go-server/cmd/main.go
new file mode 100644
index 0000000..8608780
--- /dev/null
+++ b/rpc/triple/pb/go-server/cmd/main.go
@@ -0,0 +1,71 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+ "dubbo.apache.org/dubbo-go/v3/server"
+
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb/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
+}
+
+func main() {
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_rpc_triple_pb_server"),
+ dubbo.WithRegistry(
+ registry.WithZookeeper(),
+ registry.WithAddress("127.0.0.1:2181"),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ srv, err := ins.NewServer(
+ server.WithServerProtocol(
+ protocol.WithTriple(),
+ protocol.WithPort(20000),
+ ),
+ )
+ 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/rpc/triple/pb/proto/greet.pb.go b/rpc/triple/pb/proto/greet.pb.go
new file mode 100644
index 0000000..a2b25c6
--- /dev/null
+++ b/rpc/triple/pb/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 v4.25.0
+// 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, 0x3e, 0x5a, 0x3c, 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, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x2f, 0x70, 0x62, 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/rpc/triple/pb/proto/greet.proto b/rpc/triple/pb/proto/greet.proto
new file mode 100644
index 0000000..476d306
--- /dev/null
+++ b/rpc/triple/pb/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/rpc/triple/pb/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/rpc/triple/pb/proto/greet.triple.go b/rpc/triple/pb/proto/greet.triple.go
new file mode 100644
index 0000000..ca19922
--- /dev/null
+++ b/rpc/triple/pb/proto/greet.triple.go
@@ -0,0 +1,122 @@
+// 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/rpc/triple/pb2/go-client/cmd/main.go b/rpc/triple/pb2/go-client/cmd/main.go
new file mode 100644
index 0000000..5675393
--- /dev/null
+++ b/rpc/triple/pb2/go-client/cmd/main.go
@@ -0,0 +1,64 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/client"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb2/proto"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+func main() {
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_rpc_triple_pb2_client"),
+ dubbo.WithRegistry(
+ registry.WithZookeeper(),
+ registry.WithAddress("127.0.0.1:2181"),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ cli, err := ins.NewClient(
+ client.WithClientProtocolTriple(),
+ client.WithClientSerialization(constant.ProtobufSerialization),
+ )
+
+ if err != nil {
+ panic(err)
+ }
+
+ svc, err := greet.NewGreetService(cli)
+ if err != nil {
+ panic(err)
+ }
+
+ name_str := "hello world"
+ resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: &name_str})
+ if err != nil {
+ logger.Error(err)
+ }
+ logger.Infof("Greet response: %s", resp)
+}
diff --git a/rpc/triple/pb2/go-server/cmd/main.go b/rpc/triple/pb2/go-server/cmd/main.go
new file mode 100644
index 0000000..aad81bc
--- /dev/null
+++ b/rpc/triple/pb2/go-server/cmd/main.go
@@ -0,0 +1,71 @@
+/*
+ * 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"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+ "dubbo.apache.org/dubbo-go/v3/server"
+
+ greet "github.com/apache/dubbo-go-samples/rpc/triple/pb2/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
+}
+
+func main() {
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_rpc_triple_pb2_server"),
+ dubbo.WithRegistry(
+ registry.WithZookeeper(),
+ registry.WithAddress("127.0.0.1:2181"),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ srv, err := ins.NewServer(
+ server.WithServerProtocol(
+ protocol.WithTriple(),
+ protocol.WithPort(20000),
+ ),
+ )
+ 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/rpc/triple/pb2/proto/greet.pb.go b/rpc/triple/pb2/proto/greet.pb.go
new file mode 100644
index 0000000..90ad775
--- /dev/null
+++ b/rpc/triple/pb2/proto/greet.pb.go
@@ -0,0 +1,229 @@
+//
+// 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 v4.25.0
+// 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,req,name=name" 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 && x.Name != nil {
+ return *x.Name
+ }
+ return ""
+}
+
+type GreetResponse struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ Greeting *string `protobuf:"bytes,1,req,name=greeting" 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 && x.Greeting != 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, 0x02,
+ 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, 0x02, 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, 0x3f, 0x5a, 0x3d, 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, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x2f, 0x70, 0x62, 0x32,
+ 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x67, 0x72, 0x65, 0x65, 0x74,
+}
+
+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/rpc/triple/pb2/proto/greet.proto b/rpc/triple/pb2/proto/greet.proto
new file mode 100644
index 0000000..012b853
--- /dev/null
+++ b/rpc/triple/pb2/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 = "proto2";
+
+package greet;
+
+option go_package = "github.com/apache/dubbo-go-samples/rpc/triple/pb2/proto;greet";
+
+message GreetRequest {
+ required string name = 1;
+}
+
+message GreetResponse {
+ required string greeting = 1;
+}
+
+service GreetService {
+ rpc Greet(GreetRequest) returns (GreetResponse) {}
+}
\ No newline at end of file
diff --git a/rpc/triple/pb2/proto/greet.triple.go b/rpc/triple/pb2/proto/greet.triple.go
new file mode 100644
index 0000000..ca19922
--- /dev/null
+++ b/rpc/triple/pb2/proto/greet.triple.go
@@ -0,0 +1,122 @@
+// 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/start_integrate_test.sh b/start_integrate_test.sh
index 87c1758..1ace375 100755
--- a/start_integrate_test.sh
+++ b/start_integrate_test.sh
@@ -81,6 +81,9 @@
array+=("compatibility/rpc/triple/pb2")
array+=("rpc/grpc")
+array+=("rpc/triple/pb")
+array+=("rpc/triple/pb2")
+array+=("rpc/triple/pb-json")
# tls
#array+=("compatibility/tls/dubbo")# tls.LoadX509KeyPair(certs{../../../x509/server1_cert.pem}, privateKey{../../../x509/server1_key.pem}) = err:open ../../../x509/server1_cert.pem: no such file or directory
@@ -97,6 +100,10 @@
# error
array+=("error")
+#config_center
+array+=("config_center/nacos")
+array+=("config_center/zookeeper")
+
# compatibility
## registry
array+=("compatibility/registry/zookeeper")
@@ -107,21 +114,28 @@
array+=("compatibility/registry/all/zookeeper")
array+=("compatibility/registry/all/nacos")
+# config yaml
+array+=("config_yaml")
# replace tls config
echo "The prefix of certificate path of the following files were replaced to \"$(pwd)/tls\"."
-find $(pwd)/tls -type f -name '*.yml' -print0 | xargs -0 -n1
-find $(pwd)/tls -type f -name '*.yml' -print0 | xargs -0 sed -i 's#\.\.\/\.\.\/\.\.#'"$(pwd)/tls"'#g'
+find "$(pwd)/tls" -type f -name '*.yml' -print0 | xargs -0 -n1
+find "$(pwd)/tls" -type f -name '*.yml' -print0 | xargs -0 sed -i 's#\.\.\/\.\.\/\.\.#'"$(pwd)/tls"'#g'
DOCKER_DIR=$(pwd)/integrate_test/dockercompose
-docker-compose -f $DOCKER_DIR/docker-compose.yml up -d
-bash -f $DOCKER_DIR/docker-health-check.sh
-for ((i=0;i<${#array[*]};i++))
-do
- ./integrate_test.sh "${array[i]}"
- result=$?
- if [ $result -gt 0 ]; then
- docker-compose -f $DOCKER_DIR/docker-compose.yml down
- exit $result
- fi
+DOCKER_COMPOSE_CMD="docker-compose"
+
+if [ "$(docker compose version > /dev/null; echo $?)" -eq 0 ]; then
+ DOCKER_COMPOSE_CMD="docker compose"
+fi
+
+$DOCKER_COMPOSE_CMD -f "$DOCKER_DIR"/docker-compose.yml up -d
+bash -f "$DOCKER_DIR"/docker-health-check.sh
+for ((i = 0; i < ${#array[*]}; i++)); do
+ ./integrate_test.sh "${array[i]}"
+ result=$?
+ if [ $result -gt 0 ]; then
+ $DOCKER_COMPOSE_CMD -f "$DOCKER_DIR"/docker-compose.yml down
+ exit $result
+ fi
done
-docker-compose -f $DOCKER_DIR/docker-compose.yml down
+$DOCKER_COMPOSE_CMD -f "$DOCKER_DIR"/docker-compose.yml down