This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
The following commit(s) were added to refs/heads/main by this push:
new b5836afd feat: Enhance samples interaction with Dubbo-java in
config_center (#1008)
b5836afd is described below
commit b5836afd92b13aa0fcc42d9d423a1e5dc965c0ad
Author: 花国栋 <[email protected]>
AuthorDate: Tue Jan 13 19:04:36 2026 +0800
feat: Enhance samples interaction with Dubbo-java in config_center (#1008)
* feat: Enhance samples interaction with Dubbo-java
(config_center:zookeeper nacos)
* feat: Enhance samples interaction with Dubbo-java
(config_center:zookeeper nacos)
* change test for config_center
* resolve copilot conversion
---
config_center/nacos/README.md | 39 ++++-
config_center/nacos/README_zh.md | 42 ++++-
config_center/nacos/go-client/cmd/main.go | 12 +-
config_center/nacos/go-server/cmd/main.go | 11 +-
config_center/nacos/java-client/pom.xml | 59 +++++++
.../java/org/example/client/NacosJavaClient.java | 88 ++++++++++
config_center/nacos/java-server/pom.xml | 53 ++++++
.../java/org/example/server/NacosJavaServer.java | 89 ++++++++++
config_center/nacos/pom.xml | 180 +++++++++++++++++++++
config_center/nacos/proto/greet.pb.go | 154 +++++++++++-------
config_center/nacos/proto/greet.proto | 5 +-
config_center/nacos/proto/greet.triple.go | 2 +-
config_center/zookeeper/README.md | 40 ++++-
config_center/zookeeper/README_zh.md | 44 ++++-
config_center/zookeeper/go-client/cmd/main.go | 10 +-
config_center/zookeeper/go-server/cmd/main.go | 9 +-
config_center/zookeeper/java-client/pom.xml | 59 +++++++
.../org/example/client/ZookeeperJavaClient.java | 97 +++++++++++
config_center/zookeeper/java-server/pom.xml | 53 ++++++
.../org/example/server/ZookeeperJavaServer.java | 101 ++++++++++++
config_center/zookeeper/pom.xml | 172 ++++++++++++++++++++
config_center/zookeeper/proto/greet.pb.go | 156 +++++++++++-------
config_center/zookeeper/proto/greet.proto | 3 +
config_center/zookeeper/proto/greet.triple.go | 2 +-
.../tests/integration/config_center_nacos_test.go | 4 +-
.../nacos/tests/integration/main_test.go | 2 +-
.../integration/config_center_zookeeper_test.go | 4 +-
.../zookeeper/tests/integration/main_test.go | 2 +-
28 files changed, 1324 insertions(+), 168 deletions(-)
diff --git a/config_center/nacos/README.md b/config_center/nacos/README.md
index 5fdf2f75..258a1e7c 100644
--- a/config_center/nacos/README.md
+++ b/config_center/nacos/README.md
@@ -5,6 +5,11 @@
This example shows dubbo-go's dynamic configuration feature with Nacos as
config-center.
## 2. How to run
+### Run the following commands under `integrate_test/dockercompose`:
+
+```
+docker compose up -d nacos zookeeper
+```
### Configure the configuration file into nacos
@@ -22,10 +27,11 @@ dubbo:
provider:
services:
GreeterProvider:
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
```
Open `https://localhost:8848/nacos/` with browser, make sure the relevant
configuration is already in place in nacos.
+If there is no preexisting configuration, that is fine as well, because the
sample code already includes logic to first push the configuration to the
config center.
### Start an instance with nacos as the configuration center
@@ -59,14 +65,39 @@ if err := srv.Serve(); err != nil {
}
```
-### Run client
+### Run go server
-```shell
+```
+$ go run ./go-server/cmd/main.go
+```
+
+### Run go client
+
+```
$ go run ./go-client/cmd/main.go
```
+### Before run java server/client
+```
+mvn clean compile
+```
+### Run Java server(Windows)
+```
+mvn -pl java-server exec:java
"-Dexec.mainClass=org.example.server.NacosJavaServer"
+```
+
+### Run Java client(Windows)
+```
+mvn -pl java-client exec:java
"-Dexec.mainClass=org.example.client.NacosJavaClient"
+```
+
### Expect output
+go/java client output:
+```
+Server response: Hello, this is dubbo go/java server! I received: Hello, this
is dubbo go/java client!
+```
+go/java server output:
```
-Greet response: greeting:"hello world"
+Received request: Hello, this is dubbo go/java client!
```
\ No newline at end of file
diff --git a/config_center/nacos/README_zh.md b/config_center/nacos/README_zh.md
index a6fe9e3d..2225bd89 100644
--- a/config_center/nacos/README_zh.md
+++ b/config_center/nacos/README_zh.md
@@ -5,7 +5,10 @@
本示例演示Dubbo-Go以nacos为配置中心来实现动态配置功能
## 2. 如何运行
-
+### 在 `integrate_test/dockercompose`目录下执行:
+```
+docker compose up -d nacos zookeeper
+```
### 把配置文件配置到nacos中
```yaml
@@ -22,11 +25,11 @@ dubbo:
provider:
services:
GreeterProvider:
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
```
使用浏览器打开`https://localhost:8848/nacos/` ,确保nacos中已有相关配置。
-
+如果没有预先配置也没关系,示例代码中包含了先将配置推送到配置中心的逻辑。
### 以nacos作为配置中心启动一个实例
```go
@@ -58,15 +61,38 @@ if err := srv.Serve(); err != nil {
logger.Error(err)
}
```
+### 运行go服务端
+```
+go run ./go-server/cmd/main.go
+```
-### 启动客户端
+### 运行go客户端
-```shell
-$ go run ./go-client/cmd/main.go
+```
+go run ./go-client/cmd/main.go
```
-### 预期的输出
+### 在运行Java服务端/客户端之前
+```
+mvn clean compile
+```
+### 运行Java服务端(windows)
+```
+mvn -pl java-server exec:java
"-Dexec.mainClass=org.example.server.NacosJavaServer"
+```
+
+### 运行Java客户端(windows)
+```
+ mvn -pl java-client exec:java
"-Dexec.mainClass=org.example.client.NacosJavaClient"
+```
+
+### 预期的输出
+Go/Java 客户端输出:
+```
+Server response: Hello, this is dubbo go/java server! I received: Hello, this
is dubbo go/java client!
+```
+Go/Java 服务端输出:
```
-Greet response: greeting:"hello world"
+Received request: Hello, this is dubbo go/java client!
```
\ 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
index ee67632a..481015c7 100644
--- a/config_center/nacos/go-client/cmd/main.go
+++ b/config_center/nacos/go-client/cmd/main.go
@@ -40,6 +40,8 @@ import (
const configCenterNacosClientConfig = `## set in config center, group is
'dubbo', dataid is 'dubbo-go-samples-configcenter-nacos-client', namespace is
default
dubbo:
+ application:
+ name: dubbo-go-consumer
registries:
demoZK:
protocol: zookeeper
@@ -49,7 +51,7 @@ dubbo:
references:
GreeterClientImpl:
protocol: tri
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
`
func main() {
@@ -73,7 +75,7 @@ func main() {
}
success, err := configClient.PublishConfig(vo.ConfigParam{
- DataId: "dubbo-go-samples-configcenter-nacos-client",
+ DataId: "dubbo-go-samples-configcenter-nacos-go-client",
Group: "dubbo",
Content: configCenterNacosClientConfig,
})
@@ -87,7 +89,7 @@ func main() {
time.Sleep(time.Second * 10)
nacosOption := config_center.WithNacos()
- dataIdOption :=
config_center.WithDataID("dubbo-go-samples-configcenter-nacos-client")
+ dataIdOption :=
config_center.WithDataID("dubbo-go-samples-configcenter-nacos-go-client")
addressOption := config_center.WithAddress("127.0.0.1:8848")
groupOption := config_center.WithGroup("dubbo")
ins, err := dubbo.NewInstance(
@@ -107,9 +109,9 @@ func main() {
panic(err)
}
- resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name:
"hello world"})
+ resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name:
"Hello, this is dubbo go client!"})
if err != nil {
logger.Error(err)
}
- logger.Infof("Greet response: %s", resp)
+ logger.Infof("Server response: %s", resp)
}
diff --git a/config_center/nacos/go-server/cmd/main.go
b/config_center/nacos/go-server/cmd/main.go
index f6dca780..c03e7330 100644
--- a/config_center/nacos/go-server/cmd/main.go
+++ b/config_center/nacos/go-server/cmd/main.go
@@ -42,12 +42,15 @@ type GreetTripleServer struct {
}
func (srv *GreetTripleServer) Greet(ctx context.Context, req
*greet.GreetRequest) (*greet.GreetResponse, error) {
- resp := &greet.GreetResponse{Greeting: req.Name}
+ logger.Info("Received request:" + req.Name)
+ resp := &greet.GreetResponse{Greeting: "Hello, this is dubbo go
server!" + " I received: " + 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:
+ application:
+ name: dubbo-go-provider
registries:
demoZK:
protocol: zookeeper
@@ -60,7 +63,7 @@ dubbo:
provider:
services:
GreeterProvider:
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
`
func main() {
@@ -84,7 +87,7 @@ func main() {
}
success, err := configClient.PublishConfig(vo.ConfigParam{
- DataId: "dubbo-go-samples-configcenter-nacos-server",
+ DataId: "dubbo-go-samples-configcenter-nacos-go-server",
Group: "dubbo",
Content: configCenterNacosServerConfig,
})
@@ -98,7 +101,7 @@ func main() {
time.Sleep(time.Second * 10)
nacosOption := config_center.WithNacos()
- dataIdOption :=
config_center.WithDataID("dubbo-go-samples-configcenter-nacos-server")
+ dataIdOption :=
config_center.WithDataID("dubbo-go-samples-configcenter-nacos-go-server")
addressOption := config_center.WithAddress("127.0.0.1:8848")
groupOption := config_center.WithGroup("dubbo")
ins, err := dubbo.NewInstance(
diff --git a/config_center/nacos/java-client/pom.xml
b/config_center/nacos/java-client/pom.xml
new file mode 100644
index 00000000..96535def
--- /dev/null
+++ b/config_center/nacos/java-client/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.example</groupId>
+ <artifactId>nacos-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>java-client</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty-shaded</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.example</groupId>
+ <artifactId>java-server</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git
a/config_center/nacos/java-client/src/main/java/org/example/client/NacosJavaClient.java
b/config_center/nacos/java-client/src/main/java/org/example/client/NacosJavaClient.java
new file mode 100644
index 00000000..5682eeee
--- /dev/null
+++
b/config_center/nacos/java-client/src/main/java/org/example/client/NacosJavaClient.java
@@ -0,0 +1,88 @@
+/*
+ * 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 org.example.client;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.config.ConfigService;
+import greet.GreetService;
+import greet.GreetRequest;
+import greet.GreetResponse;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import java.util.Properties;
+
+public class NacosJavaClient {
+ // Nacos server address (used as config center)
+ private static final String NACOS_ADDR = "127.0.0.1:8848";
+ // Zookeeper address (used as registry)
+ private static final String ZK_ADDR = "127.0.0.1:2181";
+ // DataId used in Nacos config center
+ private static final String DATA_ID =
"dubbo-go-samples-configcenter-nacos-java-client";
+ // Nacos group
+ private static final String GROUP = "dubbo";
+ // Configuration content pushed to Nacos config center
+ // Dubbo will load these as consumer / registry / protocol configs
+ private static final String CONFIG_CONTENT =
+ "dubbo.application.name=dubbo-java-consumer\n" +
+ "dubbo.registry.address=zookeeper://" + ZK_ADDR + "\n" +
+ "dubbo.protocol.name=tri\n" +
+ "dubbo.consumer.timeout=10000\n";
+
+ public static void main(String[] args) throws Exception {
+ //Publish Dubbo config to Nacos config center
+ Properties properties = new Properties();
+ properties.put("serverAddr", NACOS_ADDR);
+ ConfigService configService =
NacosFactory.createConfigService(properties);
+ boolean success = configService.publishConfig(DATA_ID, GROUP,
CONFIG_CONTENT);
+ if (success) {
+ System.out.println(" Succeeded to publish config to Nacos,
DATA_ID= " + DATA_ID);
+ } else {
+ System.err.println(" Failed to publish config to Nacos ");
+ }
+
+
+ ConfigCenterConfig configCenter = new ConfigCenterConfig();
+ configCenter.setAddress("nacos://" + NACOS_ADDR);
+ configCenter.setConfigFile(DATA_ID);
+ configCenter.setGroup(GROUP);
+
+ // Create reference config, only bind interface here
+ ReferenceConfig<GreetService> reference = new ReferenceConfig<>();
+ reference.setInterface(GreetService.class);
+
+ // Start DubboBootstrap with config center and reference
+ DubboBootstrap bootstrap = DubboBootstrap.getInstance()
+ .application("dubbo-java-consumer")
+ .configCenter(configCenter)
+ .reference(reference)
+ .start();
+
+ // Get remote service proxy
+ GreetService greetService = reference.get();
+ // Build request and call remote method
+ GreetRequest request = GreetRequest.newBuilder()
+ .setName("Hello, this is dubbo java client!")
+ .build();
+
+ GreetResponse response = greetService.greet(request);
+ System.out.println("server response: " + response.getGreeting());
+
+ System.exit(0);
+ }
+}
\ No newline at end of file
diff --git a/config_center/nacos/java-server/pom.xml
b/config_center/nacos/java-server/pom.xml
new file mode 100644
index 00000000..deea751b
--- /dev/null
+++ b/config_center/nacos/java-server/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.example</groupId>
+ <artifactId>nacos-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>java-server</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty-shaded</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git
a/config_center/nacos/java-server/src/main/java/org/example/server/NacosJavaServer.java
b/config_center/nacos/java-server/src/main/java/org/example/server/NacosJavaServer.java
new file mode 100644
index 00000000..4d48cbaf
--- /dev/null
+++
b/config_center/nacos/java-server/src/main/java/org/example/server/NacosJavaServer.java
@@ -0,0 +1,89 @@
+/*
+ * 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 org.example.server;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.config.ConfigService;
+import greet.GreetService;
+import greet.GreetRequest;
+import greet.GreetResponse;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import java.util.Properties;
+
+
+public class NacosJavaServer{
+ // Nacos server address (used as config center)
+ private static final String NACOS_ADDR = "127.0.0.1:8848";
+ // Zookeeper address (used as registry)
+ private static final String ZK_ADDR = "127.0.0.1:2181";
+ // DataId used in Nacos config center
+ private static final String DATA_ID =
"dubbo-go-samples-configcenter-nacos-java-server";
+ // Nacos group
+ private static final String GROUP = "dubbo";
+ // Configuration content pushed to Nacos config center
+ // Dubbo will load these as application / registry / protocol configs
+ private static final String CONFIG_CONTENT =
+ "dubbo.application.name=dubbo-java-provider\n" +
+ "dubbo.registry.address=zookeeper://" + ZK_ADDR + "\n" +
+ "dubbo.protocol.name=tri\n" +
+ "dubbo.protocol.port=50051\n";
+ public static void main(String[] args) throws Exception {
+ // Publish Dubbo config to Nacos config center
+ Properties properties = new Properties();
+ properties.put("serverAddr", NACOS_ADDR);
+ ConfigService configService =
NacosFactory.createConfigService(properties);
+ boolean success = configService.publishConfig(DATA_ID, GROUP,
CONFIG_CONTENT);
+ if (success) {
+ System.out.println(" Succeeded to publish config to Nacos,
DATA_ID= "+DATA_ID);
+ } else {
+ System.err.println(" Failed to publish config to Nacos ");
+ }
+
+ // Tell Dubbo to use Nacos as config center
+ ConfigCenterConfig configCenter = new ConfigCenterConfig();
+ configCenter.setAddress("nacos://" + NACOS_ADDR);
+ configCenter.setConfigFile(DATA_ID);
+ configCenter.setGroup(GROUP);
+
+ // Define service: only interface and implementation
+ ServiceConfig<GreetServiceImpl> service = new ServiceConfig<>();
+ service.setInterface(GreetService.class);
+ service.setRef(new GreetServiceImpl());
+
+ // Start DubboBootstrap with config center and service
+ DubboBootstrap.getInstance()
+ .application("dubbo-java-provider")
+ .configCenter(configCenter)
+ .service(service)
+ .start()
+ .await();
+ }
+
+ // Service implementation of GreetService
+ static class GreetServiceImpl implements GreetService {
+ @Override
+ public GreetResponse greet(GreetRequest request) {
+ System.out.println("Received request: " + request.getName());
+ return GreetResponse.newBuilder()
+ .setGreeting("Hello, this is dubbo java server! I
received: " + request.getName())
+ .build();
+ }
+ }
+}
\ No newline at end of file
diff --git a/config_center/nacos/pom.xml b/config_center/nacos/pom.xml
new file mode 100644
index 00000000..5311fa0e
--- /dev/null
+++ b/config_center/nacos/pom.xml
@@ -0,0 +1,180 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.example</groupId>
+ <artifactId>nacos-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>nacos-parent</name>
+ <description>Parent POM for nacos config center project</description>
+
+ <modules>
+ <module>java-server</module>
+ <module>java-client</module>
+ </modules>
+
+ <properties>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <dubbo.version>3.2.0</dubbo.version>
+ <grpc.version>1.60.0</grpc.version>
+ <protobuf.version>3.25.1</protobuf.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-bom</artifactId>
+ <version>${grpc.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <type>pom</type>
+ <exclusions>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-client</artifactId>
+ <version>2.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-rpc-triple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-protobuf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-stub</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.4.14</version>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-api</artifactId>
+ <version>2.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-common</artifactId>
+ <version>2.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ <version>4.1.91.Final</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>kr.motd.maven</groupId>
+ <artifactId>os-maven-plugin</artifactId>
+ <version>1.7.1</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.11.0</version>
+ <configuration>
+ <source>${maven.compiler.source}</source>
+ <target>${maven.compiler.target}</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ <version>0.6.1</version>
+ <configuration>
+
<protoSourceRoot>${project.basedir}/../proto</protoSourceRoot>
+
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
+ <pluginId>grpc-java</pluginId>
+
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
+
+ <protocPlugins>
+ <protocPlugin>
+ <id>dubbo</id>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-compiler</artifactId>
+ <version>${dubbo.version}</version>
+
<mainClass>org.apache.dubbo.gen.tri.Dubbo3TripleGenerator</mainClass>
+ </protocPlugin>
+ </protocPlugins>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>compile-custom</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
diff --git a/config_center/nacos/proto/greet.pb.go
b/config_center/nacos/proto/greet.pb.go
index 6e31a19f..674090c5 100644
--- a/config_center/nacos/proto/greet.pb.go
+++ b/config_center/nacos/proto/greet.pb.go
@@ -16,22 +16,17 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
-// protoc-gen-go v1.36.6
-// protoc v6.31.1
-// source: greet.proto
+// protoc-gen-go v1.31.0
+// protoc v6.33.1
+// source: proto/greet.proto
package greet
-import (
- reflect "reflect"
- sync "sync"
- unsafe "unsafe"
-)
-
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
-
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ reflect "reflect"
+ sync "sync"
)
const (
@@ -42,17 +37,20 @@ const (
)
type GreetRequest struct {
- state protoimpl.MessageState `protogen:"open.v1"`
- Name string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
- unknownFields protoimpl.UnknownFields
+ 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{}
- mi := &file_greet_proto_msgTypes[0]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
+ if protoimpl.UnsafeEnabled {
+ mi := &file_proto_greet_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *GreetRequest) String() string {
@@ -62,8 +60,8 @@ func (x *GreetRequest) String() string {
func (*GreetRequest) ProtoMessage() {}
func (x *GreetRequest) ProtoReflect() protoreflect.Message {
- mi := &file_greet_proto_msgTypes[0]
- if x != nil {
+ mi := &file_proto_greet_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -75,7 +73,7 @@ func (x *GreetRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GreetRequest.ProtoReflect.Descriptor instead.
func (*GreetRequest) Descriptor() ([]byte, []int) {
- return file_greet_proto_rawDescGZIP(), []int{0}
+ return file_proto_greet_proto_rawDescGZIP(), []int{0}
}
func (x *GreetRequest) GetName() string {
@@ -86,17 +84,20 @@ func (x *GreetRequest) GetName() string {
}
type GreetResponse struct {
- state protoimpl.MessageState `protogen:"open.v1"`
- Greeting string
`protobuf:"bytes,1,opt,name=greeting,proto3" json:"greeting,omitempty"`
- unknownFields protoimpl.UnknownFields
+ 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{}
- mi := &file_greet_proto_msgTypes[1]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
+ if protoimpl.UnsafeEnabled {
+ mi := &file_proto_greet_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *GreetResponse) String() string {
@@ -106,8 +107,8 @@ func (x *GreetResponse) String() string {
func (*GreetResponse) ProtoMessage() {}
func (x *GreetResponse) ProtoReflect() protoreflect.Message {
- mi := &file_greet_proto_msgTypes[1]
- if x != nil {
+ mi := &file_proto_greet_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -119,7 +120,7 @@ func (x *GreetResponse) ProtoReflect() protoreflect.Message
{
// Deprecated: Use GreetResponse.ProtoReflect.Descriptor instead.
func (*GreetResponse) Descriptor() ([]byte, []int) {
- return file_greet_proto_rawDescGZIP(), []int{1}
+ return file_proto_greet_proto_rawDescGZIP(), []int{1}
}
func (x *GreetResponse) GetGreeting() string {
@@ -129,36 +130,46 @@ func (x *GreetResponse) GetGreeting() string {
return ""
}
-var File_greet_proto protoreflect.FileDescriptor
-
-const file_greet_proto_rawDesc = "" +
- "\n" +
- "\vgreet.proto\x12\x05greet\"\"\n" +
- "\fGreetRequest\x12\x12\n" +
- "\x04name\x18\x01 \x01(\tR\x04name\"+\n" +
- "\rGreetResponse\x12\x1a\n" +
- "\bgreeting\x18\x01 \x01(\tR\bgreeting2D\n" +
- "\fGreetService\x124\n" +
-
"\x05Greet\x12\x13.greet.GreetRequest\x1a\x14.greet.GreetResponse\"\x00BDZBgithub.com/apache/dubbo-go-samples/config_center/nacos/proto;greetb\x06proto3"
+var File_proto_greet_proto protoreflect.FileDescriptor
+
+var file_proto_greet_proto_rawDesc = []byte{
+ 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 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,
0x42, 0x0a, 0x0c, 0x47,
+ 0x72, 0x65, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12,
0x32, 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, 0x42,
+ 0x4d, 0x0a, 0x05, 0x67, 0x72, 0x65, 0x65, 0x74, 0x50, 0x01, 0x5a, 0x42,
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, 0x63,
+ 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72,
0x2f, 0x6e, 0x61, 0x63,
+ 0x6f, 0x73, 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 []byte
+ file_proto_greet_proto_rawDescOnce sync.Once
+ file_proto_greet_proto_rawDescData = file_proto_greet_proto_rawDesc
)
-func file_greet_proto_rawDescGZIP() []byte {
- file_greet_proto_rawDescOnce.Do(func() {
- file_greet_proto_rawDescData =
protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_greet_proto_rawDesc),
len(file_greet_proto_rawDesc)))
+func file_proto_greet_proto_rawDescGZIP() []byte {
+ file_proto_greet_proto_rawDescOnce.Do(func() {
+ file_proto_greet_proto_rawDescData =
protoimpl.X.CompressGZIP(file_proto_greet_proto_rawDescData)
})
- return file_greet_proto_rawDescData
+ return file_proto_greet_proto_rawDescData
}
-var file_greet_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
-var file_greet_proto_goTypes = []any{
+var file_proto_greet_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_proto_greet_proto_goTypes = []interface{}{
(*GreetRequest)(nil), // 0: greet.GreetRequest
(*GreetResponse)(nil), // 1: greet.GreetResponse
}
-var file_greet_proto_depIdxs = []int32{
+var file_proto_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
@@ -168,26 +179,53 @@ var file_greet_proto_depIdxs = []int32{
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 {
+func init() { file_proto_greet_proto_init() }
+func file_proto_greet_proto_init() {
+ if File_proto_greet_proto != nil {
return
}
+ if !protoimpl.UnsafeEnabled {
+ file_proto_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_proto_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:
unsafe.Slice(unsafe.StringData(file_greet_proto_rawDesc),
len(file_greet_proto_rawDesc)),
+ RawDescriptor: file_proto_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,
+ GoTypes: file_proto_greet_proto_goTypes,
+ DependencyIndexes: file_proto_greet_proto_depIdxs,
+ MessageInfos: file_proto_greet_proto_msgTypes,
}.Build()
- File_greet_proto = out.File
- file_greet_proto_goTypes = nil
- file_greet_proto_depIdxs = nil
+ File_proto_greet_proto = out.File
+ file_proto_greet_proto_rawDesc = nil
+ file_proto_greet_proto_goTypes = nil
+ file_proto_greet_proto_depIdxs = nil
}
diff --git a/config_center/nacos/proto/greet.proto
b/config_center/nacos/proto/greet.proto
index 323eeb3d..d546d453 100644
--- a/config_center/nacos/proto/greet.proto
+++ b/config_center/nacos/proto/greet.proto
@@ -20,6 +20,9 @@ syntax = "proto3";
package greet;
option go_package =
"github.com/apache/dubbo-go-samples/config_center/nacos/proto;greet";
+option java_package = "greet";
+option java_outer_classname = "GreetServiceOuterClass";
+option java_multiple_files = true;
message GreetRequest {
string name = 1;
@@ -30,5 +33,5 @@ message GreetResponse {
}
service GreetService {
- rpc Greet(GreetRequest) returns (GreetResponse) {}
+ 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
index 6f906938..1df73466 100644
--- a/config_center/nacos/proto/greet.triple.go
+++ b/config_center/nacos/proto/greet.triple.go
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-triple. DO NOT EDIT.
//
-// Source: greet.proto
+// Source: proto/greet.proto
package greet
import (
diff --git a/config_center/zookeeper/README.md
b/config_center/zookeeper/README.md
index 7a10d8ef..f85c2ac1 100644
--- a/config_center/zookeeper/README.md
+++ b/config_center/zookeeper/README.md
@@ -5,7 +5,11 @@
This example shows dubbo-go's dynamic configuration feature with Zookeeper as
config-center.
## 2. How to run
+### Run the following commands under `integrate_test/dockercompose`:
+```
+docker compose up -d zookeeper
+```
### Configure the configuration file into zookeeper
```yaml
@@ -22,10 +26,11 @@ dubbo:
provider:
services:
GreeterProvider:
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
```
-Open the local zookeeper client to see if the configuration is successful
+Open the local zookeeper client to see if the configuration is successful.
+If there is no preexisting configuration, that is fine as well, because the
sample code already includes logic to first push the configuration to the
config center.
### Start an instance with zookeeper as the configuration center
@@ -59,14 +64,39 @@ if err := srv.Serve(); err != nil {
}
```
-### Run client
+### Run go server
+
+```
+$ go run ./go-server/cmd/main.go
+```
-```shell
+### Run go client
+
+```
$ go run ./go-client/cmd/main.go
```
+### Before run java server/client
+```
+mvn clean compile
+```
+### Run Java server(Windows)
+```
+mvn -pl java-server exec:java
"-Dexec.mainClass=org.example.server.ZookeeperJavaServer"
+```
+
+### Run Java client(Windows)
+```
+mvn -pl java-client exec:java
"-Dexec.mainClass=org.example.client.ZookeeperJavaClient"
+```
+
### Expect output
+go/java client output:
+```
+Server response: Hello, this is dubbo go/java server! I received: Hello, this
is dubbo go/java client!
+```
+go/java server output:
```
-Greet response: greeting:"hello world"
+Received request: Hello, this is dubbo go/java client!
```
\ No newline at end of file
diff --git a/config_center/zookeeper/README_zh.md
b/config_center/zookeeper/README_zh.md
index 408b6058..66903e83 100644
--- a/config_center/zookeeper/README_zh.md
+++ b/config_center/zookeeper/README_zh.md
@@ -5,7 +5,10 @@
本示例演示Dubbo-Go以ZooKeeper为配置中心来实现动态配置功能
## 2. 如何运行
-
+### 在 `integrate_test/dockercompose` 目录下执行:
+```
+docker compose up -d zookeeper
+```
### 把配置文件配置到zookeeper中
```yaml
@@ -22,10 +25,11 @@ dubbo:
provider:
services:
GreeterProvider:
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
```
-打开本地ZooKeeper客户端查看配置是否成功
+打开本地ZooKeeper客户端查看配置是否成功。
+如果没有预先配置也没关系,示例代码中包含了先将配置推送到配置中心的逻辑。
### 以zookeeper作为配置中心启动一个实例
@@ -59,14 +63,38 @@ if err := srv.Serve(); err != nil {
}
```
-### 启动客户端
+### 运行go服务端
+```
+go run ./go-server/cmd/main.go
+```
+
+### 运行go客户端
-```shell
-$ go run ./go-client/cmd/main.go
+```
+go run ./go-client/cmd/main.go
```
-### 预期的输出
+### 在运行Java服务端/客户端之前
+```
+mvn clean compile
+```
+### 运行Java服务端(windows)
+```
+mvn -pl java-server exec:java
"-Dexec.mainClass=org.example.server.ZookeeperJavaServer"
+```
+
+### 运行Java客户端(windows)
+```
+mvn -pl java-client exec:java
"-Dexec.mainClass=org.example.client.ZookeeperJavaClient"
+```
+
+### 预期的输出
+Go/Java 客户端输出:
+```
+Server response: Hello, this is dubbo go/java server! I received: Hello, this
is dubbo go/java client!
+```
+Go/Java 服务端输出:
```
-Greet response: greeting:"hello world"
+Received request: Hello, this is dubbo go/java client!
```
\ 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
index e6d5a668..188d7569 100644
--- a/config_center/zookeeper/go-client/cmd/main.go
+++ b/config_center/zookeeper/go-client/cmd/main.go
@@ -52,7 +52,7 @@ func main() {
// configure Dubbo instance
zkOption := config_center.WithZookeeper()
- dataIdOption :=
config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-client")
+ dataIdOption :=
config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-go-client")
addressOption := config_center.WithAddress("127.0.0.1:2181")
groupOption := config_center.WithGroup("dubbogo")
@@ -82,12 +82,12 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
- resp, err := svc.Greet(ctx, &greet.GreetRequest{Name: "hello world"})
+ resp, err := svc.Greet(ctx, &greet.GreetRequest{Name: "Hello, this is
dubbo go client!"})
if err != nil {
logger.Errorf("Failed to call Greet service: %v", err)
return
}
- logger.Infof("Greet response: %s", resp)
+ logger.Infof("Server response: %s", resp)
}
func writeRuleToConfigCenter() error {
@@ -99,7 +99,7 @@ func writeRuleToConfigCenter() error {
defer c.Close() // ensure resource cleanup
valueBytes := []byte(configCenterZKClientConfig)
- path :=
"/dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-client"
+ path :=
"/dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-go-client"
// ensure path starts with '/'
if !strings.HasPrefix(path, "/") {
@@ -159,5 +159,5 @@ dubbo:
references:
GreeterClientImpl:
protocol: tri
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
`
diff --git a/config_center/zookeeper/go-server/cmd/main.go
b/config_center/zookeeper/go-server/cmd/main.go
index 2e819aa5..8a52e304 100644
--- a/config_center/zookeeper/go-server/cmd/main.go
+++ b/config_center/zookeeper/go-server/cmd/main.go
@@ -45,7 +45,8 @@ type GreetTripleServer struct {
func (srv *GreetTripleServer) Greet(ctx context.Context, req
*greet.GreetRequest) (*greet.GreetResponse, error) {
// reference ctx to avoid unused parameter warning
_ = ctx
- resp := &greet.GreetResponse{Greeting: req.Name}
+ logger.Info("Received request:" + req.Name)
+ resp := &greet.GreetResponse{Greeting: "Hello, this is dubbo go
server!" + " I received: " + req.Name}
return resp, nil
}
@@ -62,7 +63,7 @@ func main() {
ins, err := dubbo.NewInstance(
dubbo.WithConfigCenter(
config_center.WithZookeeper(),
-
config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-server"),
+
config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-go-server"),
config_center.WithAddress("127.0.0.1:2181"),
config_center.WithGroup("dubbogo"),
),
@@ -103,7 +104,7 @@ dubbo:
provider:
services:
GreeterProvider:
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
`
// ensurePath Ensure the path exists (removed because it is unused)
@@ -117,7 +118,7 @@ func writeRuleToConfigCenter() error {
defer c.Close() // Ensure the connection is closed
valueBytes := []byte(configCenterZKServerConfig)
- path :=
"/dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-server"
+ path :=
"/dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-go-server"
// Ensure the path starts with '/'
if !strings.HasPrefix(path, "/") {
diff --git a/config_center/zookeeper/java-client/pom.xml
b/config_center/zookeeper/java-client/pom.xml
new file mode 100644
index 00000000..ba8f5124
--- /dev/null
+++ b/config_center/zookeeper/java-client/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.example</groupId>
+ <artifactId>zookeeper-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>java-client</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty-shaded</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.example</groupId>
+ <artifactId>java-server</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git
a/config_center/zookeeper/java-client/src/main/java/org/example/client/ZookeeperJavaClient.java
b/config_center/zookeeper/java-client/src/main/java/org/example/client/ZookeeperJavaClient.java
new file mode 100644
index 00000000..c37adc09
--- /dev/null
+++
b/config_center/zookeeper/java-client/src/main/java/org/example/client/ZookeeperJavaClient.java
@@ -0,0 +1,97 @@
+/*
+ * 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 org.example.client;
+
+import greet.GreetService;
+import greet.GreetRequest;
+import greet.GreetResponse;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import java.nio.charset.StandardCharsets;
+
+public class ZookeeperJavaClient {
+ // Zookeeper address (used as both registry and config center)
+ private static final String ZK_ADDR = "127.0.0.1:2181";
+ // DataId used in Zookeeper config center
+ private static final String DATA_ID =
"dubbo-go-samples-configcenter-zookeeper-java-client";
+ // Config center group
+ private static final String GROUP = "dubbogo";
+ // Configuration content pushed to Zookeeper config center
+ // Dubbo will load these as application / registry / protocol configs
+ private static final String CONFIG_CONTENT =
+ "dubbo.application.name=dubbo-java-consumer\n" +
+ "dubbo.registry.address=zookeeper://" + ZK_ADDR + "\n" +
+ "dubbo.protocol.name=tri\n";
+
+ public static void main(String[] args) throws Exception {
+ // Publish Dubbo config to Zookeeper config center
+ String configPath = "/dubbo/config/" + GROUP + "/" + DATA_ID;
+ CuratorFramework client = CuratorFrameworkFactory.builder()
+ .connectString(ZK_ADDR)
+ .retryPolicy(new ExponentialBackoffRetry(1000, 3))
+ .build();
+ client.start();
+ try {
+ byte[] data = CONFIG_CONTENT.getBytes(StandardCharsets.UTF_8);
+ if (client.checkExists().forPath(configPath) == null) {
+ client.create()
+ .creatingParentsIfNeeded()
+ .forPath(configPath, data);
+ System.out.println("Created client config in ZK, path=" +
configPath);
+ } else {
+ client.setData().forPath(configPath, data);
+ System.out.println("Updated client config in ZK, path=" +
configPath);
+ }
+ } finally {
+ client.close();
+ }
+
+ // Tell Dubbo to use Zookeeper as config center
+ ConfigCenterConfig configCenter = new ConfigCenterConfig();
+ configCenter.setAddress("zookeeper://" + ZK_ADDR);
+ configCenter.setGroup(GROUP);
+ configCenter.setConfigFile(DATA_ID);
+
+ // Create reference config, only bind interface here
+ ReferenceConfig<GreetService> reference = new ReferenceConfig<>();
+ reference.setInterface(GreetService.class);
+
+ // Start DubboBootstrap and load reference from config center
+ DubboBootstrap bootstrap = DubboBootstrap.getInstance()
+ .application("dubbo-java-consumer")
+ .configCenter(configCenter)
+ .reference(reference)
+ .start();
+
+ //Get remote service proxy
+ GreetService greetService = reference.get();
+ //Build request and call remote method
+ GreetRequest request = GreetRequest.newBuilder()
+ .setName("Hello, this is dubbo java client!")
+ .build();
+
+ GreetResponse response = greetService.greet(request);
+ System.out.println("Server response: " + response.getGreeting());
+
+ System.exit(0);
+ }
+}
\ No newline at end of file
diff --git a/config_center/zookeeper/java-server/pom.xml
b/config_center/zookeeper/java-server/pom.xml
new file mode 100644
index 00000000..49ce21b6
--- /dev/null
+++ b/config_center/zookeeper/java-server/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.example</groupId>
+ <artifactId>zookeeper-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>java-server</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty-shaded</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git
a/config_center/zookeeper/java-server/src/main/java/org/example/server/ZookeeperJavaServer.java
b/config_center/zookeeper/java-server/src/main/java/org/example/server/ZookeeperJavaServer.java
new file mode 100644
index 00000000..b87acb97
--- /dev/null
+++
b/config_center/zookeeper/java-server/src/main/java/org/example/server/ZookeeperJavaServer.java
@@ -0,0 +1,101 @@
+/*
+ * 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 org.example.server;
+
+import greet.GreetRequest;
+import greet.GreetResponse;
+import greet.GreetService;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+
+import java.nio.charset.StandardCharsets;
+
+public class ZookeeperJavaServer {
+ // Zookeeper address (used as both registry and config center)
+ private static final String ZK_ADDR = "127.0.0.1:2181";
+ // DataId used in Zookeeper config center
+ private static final String DATA_ID =
"dubbo-go-samples-configcenter-zookeeper-java-server";
+ // Config center group
+ private static final String GROUP = "dubbogo";
+ // Configuration content pushed to Zookeeper config center
+ // Dubbo will load these as application / registry / protocol configs
+ private static final String CONFIG_CONTENT =
+ "dubbo.application.name=dubbo-java-provider\n" +
+ "dubbo.registry.address=zookeeper://" + ZK_ADDR + "\n" +
+ "dubbo.protocol.name=tri\n" +
+ "dubbo.protocol.port=50051\n";
+ public static void main(String[] args) throws Exception {
+ // Publish Dubbo config to Zookeeper config center
+ String configPath = "/dubbo/config/" + GROUP + "/" + DATA_ID;
+ CuratorFramework client = CuratorFrameworkFactory
+ .builder()
+ .connectString(ZK_ADDR)
+ .retryPolicy(new ExponentialBackoffRetry(1000, 3))
+ .build();
+ client.start();
+
+ try {
+ if (client.checkExists().forPath(configPath) == null) {
+ client.create()
+ .creatingParentsIfNeeded()
+ .forPath(configPath,
CONFIG_CONTENT.getBytes(StandardCharsets.UTF_8));
+ System.out.println("Config created in ZK, path=" + configPath);
+ } else {
+ client.setData()
+ .forPath(configPath,
CONFIG_CONTENT.getBytes(StandardCharsets.UTF_8));
+ System.out.println("Config updated in ZK, path=" + configPath);
+ }
+ } finally {
+ client.close();
+ }
+
+ // Tell Dubbo to use Zookeeper as config center
+ ConfigCenterConfig configCenter = new ConfigCenterConfig();
+ configCenter.setAddress("zookeeper://" + ZK_ADDR);
+ configCenter.setGroup(GROUP);
+ configCenter.setConfigFile(DATA_ID);
+
+ // Define service: only interface and implementation
+ ServiceConfig<GreetService> service = new ServiceConfig<>();
+ service.setInterface(GreetService.class);
+ service.setRef(new GreetServiceImpl());
+
+ // Start DubboBootstrap and load reference from config center
+ DubboBootstrap.getInstance()
+ .application("dubbo-java-provider")
+ .configCenter(configCenter)
+ .service(service)
+ .start()
+ .await();
+ }
+
+ // Service implementation of GreetService
+ static class GreetServiceImpl implements GreetService {
+ @Override
+ public GreetResponse greet(GreetRequest request) {
+ System.out.println("Received request: " + request.getName());
+ return GreetResponse.newBuilder()
+ .setGreeting("Hello, this is dubbo java server! I
received: " + request.getName())
+ .build();
+ }
+ }
+}
\ No newline at end of file
diff --git a/config_center/zookeeper/pom.xml b/config_center/zookeeper/pom.xml
new file mode 100644
index 00000000..1858ebc3
--- /dev/null
+++ b/config_center/zookeeper/pom.xml
@@ -0,0 +1,172 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.example</groupId>
+ <artifactId>zookeeper-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>zookeeper-parent</name>
+ <description>Parent POM for zookeeper config center project</description>
+
+ <modules>
+ <module>java-server</module>
+ <module>java-client</module>
+ </modules>
+
+ <properties>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <dubbo.version>3.2.0</dubbo.version>
+ <grpc.version>1.60.0</grpc.version>
+ <protobuf.version>3.25.1</protobuf.version>
+ <zookeeper.version>3.8.3</zookeeper.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-bom</artifactId>
+ <version>${grpc.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <type>pom</type>
+ <exclusions>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-rpc-triple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ <version>${zookeeper.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-protobuf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-stub</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.4.14</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>kr.motd.maven</groupId>
+ <artifactId>os-maven-plugin</artifactId>
+ <version>1.7.1</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.11.0</version>
+ <configuration>
+ <source>${maven.compiler.source}</source>
+ <target>${maven.compiler.target}</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ <version>0.6.1</version>
+ <configuration>
+
<protoSourceRoot>${project.basedir}/../proto</protoSourceRoot>
+
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
+ <pluginId>grpc-java</pluginId>
+
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
+
+ <protocPlugins>
+ <protocPlugin>
+ <id>dubbo</id>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-compiler</artifactId>
+ <version>${dubbo.version}</version>
+
<mainClass>org.apache.dubbo.gen.tri.Dubbo3TripleGenerator</mainClass>
+ </protocPlugin>
+ </protocPlugins>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>compile-custom</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
diff --git a/config_center/zookeeper/proto/greet.pb.go
b/config_center/zookeeper/proto/greet.pb.go
index 354affe2..ae787ad5 100644
--- a/config_center/zookeeper/proto/greet.pb.go
+++ b/config_center/zookeeper/proto/greet.pb.go
@@ -16,22 +16,17 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
-// protoc-gen-go v1.36.6
-// protoc v6.31.1
-// source: greet.proto
+// protoc-gen-go v1.31.0
+// protoc v6.33.1
+// source: proto/greet.proto
package greet
-import (
- reflect "reflect"
- sync "sync"
- unsafe "unsafe"
-)
-
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
-
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ reflect "reflect"
+ sync "sync"
)
const (
@@ -42,17 +37,20 @@ const (
)
type GreetRequest struct {
- state protoimpl.MessageState `protogen:"open.v1"`
- Name string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
- unknownFields protoimpl.UnknownFields
+ 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{}
- mi := &file_greet_proto_msgTypes[0]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
+ if protoimpl.UnsafeEnabled {
+ mi := &file_proto_greet_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *GreetRequest) String() string {
@@ -62,8 +60,8 @@ func (x *GreetRequest) String() string {
func (*GreetRequest) ProtoMessage() {}
func (x *GreetRequest) ProtoReflect() protoreflect.Message {
- mi := &file_greet_proto_msgTypes[0]
- if x != nil {
+ mi := &file_proto_greet_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -75,7 +73,7 @@ func (x *GreetRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GreetRequest.ProtoReflect.Descriptor instead.
func (*GreetRequest) Descriptor() ([]byte, []int) {
- return file_greet_proto_rawDescGZIP(), []int{0}
+ return file_proto_greet_proto_rawDescGZIP(), []int{0}
}
func (x *GreetRequest) GetName() string {
@@ -86,17 +84,20 @@ func (x *GreetRequest) GetName() string {
}
type GreetResponse struct {
- state protoimpl.MessageState `protogen:"open.v1"`
- Greeting string
`protobuf:"bytes,1,opt,name=greeting,proto3" json:"greeting,omitempty"`
- unknownFields protoimpl.UnknownFields
+ 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{}
- mi := &file_greet_proto_msgTypes[1]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
+ if protoimpl.UnsafeEnabled {
+ mi := &file_proto_greet_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *GreetResponse) String() string {
@@ -106,8 +107,8 @@ func (x *GreetResponse) String() string {
func (*GreetResponse) ProtoMessage() {}
func (x *GreetResponse) ProtoReflect() protoreflect.Message {
- mi := &file_greet_proto_msgTypes[1]
- if x != nil {
+ mi := &file_proto_greet_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -119,7 +120,7 @@ func (x *GreetResponse) ProtoReflect() protoreflect.Message
{
// Deprecated: Use GreetResponse.ProtoReflect.Descriptor instead.
func (*GreetResponse) Descriptor() ([]byte, []int) {
- return file_greet_proto_rawDescGZIP(), []int{1}
+ return file_proto_greet_proto_rawDescGZIP(), []int{1}
}
func (x *GreetResponse) GetGreeting() string {
@@ -129,36 +130,48 @@ func (x *GreetResponse) GetGreeting() string {
return ""
}
-var File_greet_proto protoreflect.FileDescriptor
-
-const file_greet_proto_rawDesc = "" +
- "\n" +
- "\vgreet.proto\x12\x05greet\"\"\n" +
- "\fGreetRequest\x12\x12\n" +
- "\x04name\x18\x01 \x01(\tR\x04name\"+\n" +
- "\rGreetResponse\x12\x1a\n" +
- "\bgreeting\x18\x01 \x01(\tR\bgreeting2D\n" +
- "\fGreetService\x124\n" +
-
"\x05Greet\x12\x13.greet.GreetRequest\x1a\x14.greet.GreetResponse\"\x00BHZFgithub.com/apache/dubbo-go-samples/config_center/zookeeper/proto;greetb\x06proto3"
+var File_proto_greet_proto protoreflect.FileDescriptor
+
+var file_proto_greet_proto_rawDesc = []byte{
+ 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 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, 0x69, 0x0a, 0x05, 0x67, 0x72, 0x65, 0x65, 0x74, 0x42, 0x16,
0x47, 0x72, 0x65, 0x65,
+ 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x75, 0x74, 0x65,
0x72, 0x43, 0x6c, 0x61,
+ 0x73, 0x73, 0x50, 0x01, 0x5a, 0x46, 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, 0x63, 0x6f, 0x6e,
0x66, 0x69, 0x67, 0x5f,
+ 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x7a, 0x6f, 0x6f, 0x6b, 0x65,
0x65, 0x70, 0x65, 0x72,
+ 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 []byte
+ file_proto_greet_proto_rawDescOnce sync.Once
+ file_proto_greet_proto_rawDescData = file_proto_greet_proto_rawDesc
)
-func file_greet_proto_rawDescGZIP() []byte {
- file_greet_proto_rawDescOnce.Do(func() {
- file_greet_proto_rawDescData =
protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_greet_proto_rawDesc),
len(file_greet_proto_rawDesc)))
+func file_proto_greet_proto_rawDescGZIP() []byte {
+ file_proto_greet_proto_rawDescOnce.Do(func() {
+ file_proto_greet_proto_rawDescData =
protoimpl.X.CompressGZIP(file_proto_greet_proto_rawDescData)
})
- return file_greet_proto_rawDescData
+ return file_proto_greet_proto_rawDescData
}
-var file_greet_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
-var file_greet_proto_goTypes = []any{
+var file_proto_greet_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_proto_greet_proto_goTypes = []interface{}{
(*GreetRequest)(nil), // 0: greet.GreetRequest
(*GreetResponse)(nil), // 1: greet.GreetResponse
}
-var file_greet_proto_depIdxs = []int32{
+var file_proto_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
@@ -168,26 +181,53 @@ var file_greet_proto_depIdxs = []int32{
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 {
+func init() { file_proto_greet_proto_init() }
+func file_proto_greet_proto_init() {
+ if File_proto_greet_proto != nil {
return
}
+ if !protoimpl.UnsafeEnabled {
+ file_proto_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_proto_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:
unsafe.Slice(unsafe.StringData(file_greet_proto_rawDesc),
len(file_greet_proto_rawDesc)),
+ RawDescriptor: file_proto_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,
+ GoTypes: file_proto_greet_proto_goTypes,
+ DependencyIndexes: file_proto_greet_proto_depIdxs,
+ MessageInfos: file_proto_greet_proto_msgTypes,
}.Build()
- File_greet_proto = out.File
- file_greet_proto_goTypes = nil
- file_greet_proto_depIdxs = nil
+ File_proto_greet_proto = out.File
+ file_proto_greet_proto_rawDesc = nil
+ file_proto_greet_proto_goTypes = nil
+ file_proto_greet_proto_depIdxs = nil
}
diff --git a/config_center/zookeeper/proto/greet.proto
b/config_center/zookeeper/proto/greet.proto
index a0eef428..930518ed 100644
--- a/config_center/zookeeper/proto/greet.proto
+++ b/config_center/zookeeper/proto/greet.proto
@@ -20,6 +20,9 @@ syntax = "proto3";
package greet;
option go_package =
"github.com/apache/dubbo-go-samples/config_center/zookeeper/proto;greet";
+option java_package = "greet";
+option java_outer_classname = "GreetServiceOuterClass";
+option java_multiple_files = true;
message GreetRequest {
string name = 1;
diff --git a/config_center/zookeeper/proto/greet.triple.go
b/config_center/zookeeper/proto/greet.triple.go
index 6f906938..1df73466 100644
--- a/config_center/zookeeper/proto/greet.triple.go
+++ b/config_center/zookeeper/proto/greet.triple.go
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-triple. DO NOT EDIT.
//
-// Source: greet.proto
+// Source: proto/greet.proto
package greet
import (
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
index 6032b97f..bce48aed 100644
---
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
@@ -31,12 +31,12 @@ import (
)
func TestSayHello(t *testing.T) {
- req := &greet.GreetRequest{Name: "hello world"}
+ req := &greet.GreetRequest{Name: "Hello, this is dubbo go client!"}
ctx := context.Background()
reply, err := greeterProvider.Greet(ctx, req)
assert.Nil(t, err)
- assert.Equal(t, "hello world", reply.Greeting)
+ assert.Equal(t, "Hello, this is dubbo go server! I received: Hello,
this is dubbo go client!", 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
index 33152d36..67ef0a68 100644
--- a/integrate_test/config_center/nacos/tests/integration/main_test.go
+++ b/integrate_test/config_center/nacos/tests/integration/main_test.go
@@ -48,7 +48,7 @@ dubbo:
references:
GreeterClientImpl:
protocol: tri
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
`
var greeterProvider greet.GreetService
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
index 4e0e36a8..501f2709 100644
---
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
@@ -31,12 +31,12 @@ import (
)
func TestSayHello(t *testing.T) {
- req := &greet.GreetRequest{Name: "hello world"}
+ req := &greet.GreetRequest{Name: "Hello, this is dubbo go client!"}
ctx := context.Background()
reply, err := greeterProvider.Greet(ctx, req)
assert.Nil(t, err)
- assert.Equal(t, "hello world", reply.Greeting)
+ assert.Equal(t, "Hello, this is dubbo go server! I received: Hello,
this is dubbo go client!", 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
index 4ee10c57..6fa96551 100644
--- a/integrate_test/config_center/zookeeper/tests/integration/main_test.go
+++ b/integrate_test/config_center/zookeeper/tests/integration/main_test.go
@@ -49,7 +49,7 @@ dubbo:
references:
GreeterClientImpl:
protocol: tri
- interface: com.apache.dubbo.sample.basic.IGreeter
+ interface: greet.GreetService
`
var greeterProvider greet.GreetService