This is an automated email from the ASF dual-hosted git repository.

xuetaoli 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 2a01b76f fix(generic):keep Go and Java client/server consistent (#1046)
2a01b76f is described below

commit 2a01b76f8a850a8615ac28166a34213fa2a8fcec
Author: Rynzie <[email protected]>
AuthorDate: Mon Mar 16 18:50:37 2026 +0800

    fix(generic):keep Go and Java client/server consistent (#1046)
    
    * fix(generic):keep Go and Java client/server consistent
    
    * remove redundant run.sh(that will make integrate_test to panic)
    
    * exit with non-zero code when tests fail
    
    * Address Copilot review comments
---
 generic/README.md                                  | 13 ++---
 generic/README_zh.md                               | 13 ++---
 generic/go-client/cmd/client.go                    | 58 +++++++++++++---------
 generic/java-client/java-client/run.sh             |  1 -
 .../apache/dubbo/samples/ApiTripleConsumer.java    |  4 +-
 generic/java-server/java-server/run.sh             |  1 -
 .../java/org/apache/dubbo/samples/ApiProvider.java |  5 +-
 7 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/generic/README.md b/generic/README.md
index 38fb1ff2..e657de2d 100644
--- a/generic/README.md
+++ b/generic/README.md
@@ -2,21 +2,21 @@
 
 [English](README.md) | [中文](README_zh.md)
 
-This sample demonstrates how to use generic invocation with both Dubbo and 
Triple protocols for Go-Java interoperability. Generic invocation allows 
calling remote services without generating stubs or having the service 
interface locally.
+This sample demonstrates generic invocation over the Triple protocol for 
Go-Java interoperability. Generic invocation allows calling remote services 
without generating stubs or having the service interface locally.
 
 ## Layout
 
 ```
 generic/
 ├── go-server/      # Go provider (Triple protocol, port 50052)
-├── go-client/      # Go consumer with generic invocation (direct connection)
+├── go-client/      # Go consumer with generic invocation (registry discovery)
 ├── java-server/    # Java provider (Triple protocol, port 50052)
 └── java-client/    # Java consumer with generic invocation
 ```
 
 ## Prerequisites
 
-Start ZooKeeper (required by the server for service registration):
+Start ZooKeeper (required for server registration and client discovery):
 
 ```bash
 docker run -d --name zookeeper -p 2181:2181 zookeeper:3.8
@@ -38,7 +38,7 @@ cd generic/go-client/cmd
 go run .
 ```
 
-The client uses direct URL connection (`client.WithURL`) to connect to the 
server and performs generic calls via `cli.NewGenericService`. It tests both 
Dubbo protocol (port 20000) and Triple protocol (port 50052).
+ The client discovers providers from ZooKeeper via the `RegistryIDs` field on 
`ReferenceConfig` and the registry configured on `RootConfig` (using 
`AddRegistry`), and performs generic calls via `config/generic.GenericService`
 
 ## Run the Java Server
 
@@ -56,7 +56,7 @@ cd generic/java-client
 mvn clean compile exec:java 
-Dexec.mainClass="org.apache.dubbo.samples.ApiTripleConsumer"
 ```
 
-The client uses `reference.setGeneric("true")` to perform generic calls.
+The client uses `reference.setGeneric("true")` to perform generic calls and 
discovers providers from ZooKeeper.
 
 ## Tested Methods
 
@@ -95,4 +95,5 @@ All generic call tests completed
 
 - Do NOT start Go Server and Java Server at the same time. Both listen on port 
50052.
 - The Go server requires ZooKeeper for service registration.
-- The Go client uses direct URL connection and does not require ZooKeeper.
+- The Java client discovers providers from ZooKeeper.
+- The Go client discovers providers from ZooKeeper.
diff --git a/generic/README_zh.md b/generic/README_zh.md
index af18a2c4..826e51b0 100644
--- a/generic/README_zh.md
+++ b/generic/README_zh.md
@@ -2,21 +2,21 @@
 
 [English](README.md) | [中文](README_zh.md)
 
-本示例演示了如何使用 Dubbo 和 Triple 协议进行泛化调用,实现 Go 和 Java 
服务之间的互操作。泛化调用允许在没有服务接口定义的情况下调用远程服务。
+本示例演示了如何通过 Triple 协议进行泛化调用,实现 Go 和 Java 服务之间的互操作。泛化调用允许在没有服务接口定义的情况下调用远程服务。
 
 ## 目录结构
 
 ```
 generic/
 ├── go-server/      # Go 服务端(Triple 协议,端口 50052)
-├── go-client/      # Go 客户端,泛化调用(直连模式)
+├── go-client/      # Go 客户端,泛化调用(注册中心发现)
 ├── java-server/    # Java 服务端(Triple 协议,端口 50052)
 └── java-client/    # Java 客户端,泛化调用
 ```
 
 ## 前置条件
 
-启动 ZooKeeper(服务端注册服务时需要):
+启动 ZooKeeper(服务端注册和客户端发现服务都需要):
 
 ```bash
 docker run -d --name zookeeper -p 2181:2181 zookeeper:3.8
@@ -38,7 +38,7 @@ cd generic/go-client/cmd
 go run .
 ```
 
-客户端使用直连模式(`client.WithURL`)连接服务端,通过 `cli.NewGenericService` 进行泛化调用。同时测试 Dubbo 
协议(端口 20000)和 Triple 协议(端口 50052)。
+ 客户端通过 RootConfig 中的注册中心配置并在 ReferenceConfig 里通过 `RegistryIDs` 引用,从 ZooKeeper 
发现服务,并使用 config/generic.GenericService 进行泛化调用。
 
 ## 启动 Java 服务端
 
@@ -56,7 +56,7 @@ cd generic/java-client
 mvn clean compile exec:java 
-Dexec.mainClass="org.apache.dubbo.samples.ApiTripleConsumer"
 ```
 
-客户端使用 `reference.setGeneric("true")` 进行泛化调用。
+客户端使用 `reference.setGeneric("true")` 进行泛化调用,并通过 ZooKeeper 发现服务提供者。
 
 ## 测试方法
 
@@ -95,4 +95,5 @@ All generic call tests completed
 
 - 不要同时启动 Go 服务端和 Java 服务端,它们都监听 50052 端口。
 - Go 服务端需要 ZooKeeper 进行服务注册。
-- Go 客户端使用直连模式,不依赖 ZooKeeper。
+- Java 客户端通过 ZooKeeper 发现服务。
+- Go 客户端通过 ZooKeeper 发现服务。
diff --git a/generic/go-client/cmd/client.go b/generic/go-client/cmd/client.go
index acd949bc..58aad0ce 100644
--- a/generic/go-client/cmd/client.go
+++ b/generic/go-client/cmd/client.go
@@ -24,15 +24,16 @@ import (
 )
 
 import (
-       "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/filter/generic"
+       "dubbo.apache.org/dubbo-go/v3/config"
+       "dubbo.apache.org/dubbo-go/v3/config/generic"
        _ "dubbo.apache.org/dubbo-go/v3/imports"
 
        hessian "github.com/apache/dubbo-go-hessian2"
 
        "github.com/dubbogo/gost/log/logger"
+
+       tpconst "github.com/dubbogo/triple/pkg/common/constant"
 )
 
 import (
@@ -40,38 +41,47 @@ import (
 )
 
 const (
-       TripleServerURL = "tri://127.0.0.1:50052"
-       UserProvider    = "org.apache.dubbo.samples.UserProvider"
-       ServiceVersion  = "1.0.0"
+       AppName          = "generic-go-client"
+       RegistryID       = "zk"
+       ZookeeperAddress = "127.0.0.1:2181"
+       UserProvider     = "org.apache.dubbo.samples.UserProvider"
+       ServiceVersion   = "1.0.0"
 )
 
 func main() {
        hessian.RegisterPOJO(&pkg.User{})
 
-       ins, err := dubbo.NewInstance(
-               dubbo.WithName("generic-go-client"),
-       )
-       if err != nil {
+       rootConfig := config.NewRootConfigBuilder().
+               SetApplication(
+                       config.NewApplicationConfigBuilder().
+                               SetName(AppName).
+                               Build(),
+               ).
+               AddRegistry(RegistryID, &config.RegistryConfig{
+                       Protocol: "zookeeper",
+                       Address:  ZookeeperAddress,
+               }).
+               Build()
+       if err := config.Load(config.WithRootConfig(rootConfig)); err != nil {
                panic(err)
        }
 
-       cli, err := ins.NewClient(
-               client.WithClientProtocolTriple(),
-               client.WithClientSerialization(constant.Hessian2Serialization),
-       )
-       if err != nil {
-               panic(err)
+       refConf := config.ReferenceConfig{
+               InterfaceName: UserProvider,
+               RegistryIDs:   []string{RegistryID},
+               Protocol:      tpconst.TRIPLE,
+               Cluster:       "failover",
+               Group:         "triple",
+               Version:       ServiceVersion,
+               Serialization: constant.Hessian2Serialization,
+               Generic:       "true",
        }
-
-       genericService, err := cli.NewGenericService(
-               UserProvider,
-               client.WithURL(TripleServerURL),
-               client.WithVersion(ServiceVersion),
-               client.WithGroup("triple"),
-       )
-       if err != nil {
+       if err := refConf.Init(rootConfig); err != nil {
                panic(err)
        }
+       refConf.GenericLoad(AppName)
+
+       genericService := refConf.GetRPCService().(*generic.GenericService)
 
        failed := false
        failed = runGenericTests(genericService) || failed
diff --git a/generic/java-client/java-client/run.sh 
b/generic/java-client/java-client/run.sh
deleted file mode 100755
index 2884ca0c..00000000
--- a/generic/java-client/java-client/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-mvn -q -e clean package && java -jar 
target/generic-dubbo-java-client-1.0-SNAPSHOT.jar
\ No newline at end of file
diff --git 
a/generic/java-client/src/main/java/org/apache/dubbo/samples/ApiTripleConsumer.java
 
b/generic/java-client/src/main/java/org/apache/dubbo/samples/ApiTripleConsumer.java
index ff013bb7..df49510d 100644
--- 
a/generic/java-client/src/main/java/org/apache/dubbo/samples/ApiTripleConsumer.java
+++ 
b/generic/java-client/src/main/java/org/apache/dubbo/samples/ApiTripleConsumer.java
@@ -209,10 +209,10 @@ public class ApiTripleConsumer {
 
         if (failed > 0) {
             System.out.println("\n[WARN] Some tests failed!");
+            System.exit(1);
         } else {
             System.out.println("\n[OK] All tests passed!");
+            System.exit(0);
         }
-
-        System.exit(0);
     }
 }
diff --git a/generic/java-server/java-server/run.sh 
b/generic/java-server/java-server/run.sh
deleted file mode 100755
index 0fa16c68..00000000
--- a/generic/java-server/java-server/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-mvn -q -e clean package && java -jar 
target/generic-dubbo-java-server-1.0-SNAPSHOT.jar
\ No newline at end of file
diff --git 
a/generic/java-server/src/main/java/org/apache/dubbo/samples/ApiProvider.java 
b/generic/java-server/src/main/java/org/apache/dubbo/samples/ApiProvider.java
index 95b0ff73..6e9d2596 100644
--- 
a/generic/java-server/src/main/java/org/apache/dubbo/samples/ApiProvider.java
+++ 
b/generic/java-server/src/main/java/org/apache/dubbo/samples/ApiProvider.java
@@ -28,6 +28,7 @@ public class ApiProvider {
     private static final int DUBBO_PORT = 20000;
     private static final int TRIPLE_PORT = 50052;
     private static final String SERVICE_VERSION = "1.0.0";
+    private static final String ZOOKEEPER_ADDRESS = 
"zookeeper://127.0.0.1:2181";
 
     public static void main(String[] args) throws InterruptedException {
         // Dubbo protocol service (group=dubbo)
@@ -46,9 +47,9 @@ public class ApiProvider {
         tripleService.setVersion(SERVICE_VERSION);
         tripleService.setProtocol(new ProtocolConfig("tri", TRIPLE_PORT));
 
-        // Use direct export without registry
+        // Register provider to ZooKeeper
         RegistryConfig registryConfig = new RegistryConfig();
-        registryConfig.setAddress("N/A");
+        registryConfig.setAddress(ZOOKEEPER_ADDRESS);
 
         DubboBootstrap bootstrap = DubboBootstrap.getInstance();
         bootstrap.application("generic-java-server")

Reply via email to