Copilot commented on code in PR #992:
URL: https://github.com/apache/dubbo-go-samples/pull/992#discussion_r2644748371


##########
async/README.md:
##########
@@ -3,24 +3,95 @@
 [[English](README.md) | [中文](README_zh.md)]
 
 This sample showcases how to invoke Dubbo services asynchronously with the new
-`client`/`server` APIs over the Triple protocol. The client issues both a 
regular
-async call (`GetUser`) and a fire-and-forget style call (`SayHello`) while the
-server uses Protobuf serialization to serve Triple requests. Note: This sample
-demonstrates the non-blocking nature of async calls; the response can be 
obtained
-through the return value.
+`client`/`server` APIs over the Triple protocol. It demonstrates both Go-to-Go
+and Java-to-Go async interoperability.
 
-## Run the sample
+## Features
 
-1. **Start the provider**
+- **Go Client & Server**: Async calls using `client.WithAsync()`
+- **Java Client**: Async calls using `CompletableFuture` API
+- **Java Server**: Async service implementation with `CompletableFuture`
+- **Interoperability**: Java client can call Go server, Go client can call 
Java server
+
+## Run Go to Go sample
+
+1. **Start the Go server**
 
    ```bash
    go run ./async/go-server/cmd/main.go
    ```
 
-2. **Start the consumer**
+2. **Start the Go client** (connects to Go server by default)
 
    ```bash
    go run ./async/go-client/cmd/main.go
    ```
 
 The client prints "non-blocking before async callback resp: do something ... " 
and "test end" logs, demonstrating the non-blocking nature of async calls.
+
+## Run Java-Go interoperability sample
+
+This demonstrates **cross-language async calls**:
+
+- **Go client** → **Java server**
+- **Java client** → **Go server**
+
+### Prerequisites
+
+- Java 11 or higher
+- Maven 3.6+
+
+### Build Java modules
+
+From the `async` directory:
+
+```bash
+mvn clean compile
+```
+
+### Test: Go client → Java server
+
+1. **Modify the Go client URL** in `go-client/cmd/main.go`:
+
+   ```go
+   client.WithClientURL("tri://127.0.0.1:50051"),
+   ```

Review Comment:
   The documentation states that the Go client can be modified to connect to 
the Java server by changing the URL to "tri://127.0.0.1:50051", but the actual 
Go client code in go-client/cmd/main.go currently hardcodes 
"tri://127.0.0.1:20000". The README should clarify that this is the default 
configuration for Go-to-Go communication, and users need to manually change 
this line in the code to test Java interoperability as described.



##########
async/java-client/src/main/java/org/apache/dubbo/samples/async/JavaAsyncClient.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.apache.dubbo.samples.async;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import org.apache.dubbo.samples.async.proto.*;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+
+public class JavaAsyncClient {
+
+    public static void main(String[] args) throws Exception {
+        ReferenceConfig<UserProvider> userProviderRef = new 
ReferenceConfig<>();
+        userProviderRef.setInterface(UserProvider.class);
+        userProviderRef.setUrl("tri://127.0.0.1:20000");
+
+        ReferenceConfig<UserProviderV2> userProviderV2Ref = new 
ReferenceConfig<>();
+        userProviderV2Ref.setInterface(UserProviderV2.class);
+        userProviderV2Ref.setUrl("tri://127.0.0.1:20000");
+
+        DubboBootstrap bootstrap = DubboBootstrap.getInstance();
+        bootstrap.application(new ApplicationConfig("java-async-client"))
+                .reference(userProviderRef)
+                .reference(userProviderV2Ref)
+                .start();
+
+        UserProvider userProvider = userProviderRef.get();
+        UserProviderV2 userProviderV2 = userProviderV2Ref.get();
+
+        CountDownLatch latch1 = new CountDownLatch(1);
+        GetUserRequest getUserReq = 
GetUserRequest.newBuilder().setId("003").build();
+        CompletableFuture<GetUserResponse> future1 = 
userProvider.getUserAsync(getUserReq);
+
+        System.out.println("async request sent, doing other work...");
+
+        future1.whenComplete((response, throwable) -> {
+            if (throwable != null) {
+                System.err.println("error: " + throwable.getMessage());
+            } else {
+                User user = response.getUser();
+                System.out.println("received user: " + user.getName() + ", 
age: " + user.getAge());
+            }
+            latch1.countDown();
+        });
+
+        CountDownLatch latch2 = new CountDownLatch(1);
+        SayHelloRequest sayHelloReq = 
SayHelloRequest.newBuilder().setUserId("002").build();
+        CompletableFuture<SayHelloResponse> future2 = 
userProviderV2.sayHelloAsync(sayHelloReq);
+
+        future2.whenComplete((response, throwable) -> {
+            if (throwable == null) {
+                System.out.println("sayHello completed");
+            }
+            latch2.countDown();
+        });

Review Comment:
   The error handling for the second async call (sayHelloAsync) is inconsistent 
with the first. The callback at line 68-73 only checks if throwable is null and 
prints "sayHello completed", but it doesn't handle or log the error case when 
throwable is not null. This means errors in the SayHello call will be silently 
ignored. Consider adding error handling similar to the first callback to ensure 
errors are properly logged.



##########
async/README_zh.md:
##########
@@ -1,22 +1,96 @@
-# 异步 RPC Dubbo for Dubbo-go
+# Dubbo-go 异步 RPC
 
 [[English](README.md) | [中文](README_zh.md)]
 
-该示例基于新版 `client` / `server` API 展示 Triple 协议下的 Dubbo 异步调用:客户端
-在发送 `GetUser` 请求后可以继续执行其他逻辑(非阻塞调用),同时也包含 `SayHello` 
的单向调用示例。注意:本示例仅演示异步调用的非阻塞特性,实际响应可通过返回值获取。
+本示例展示了如何使用新的 `client`/`server` API 通过 Triple 协议异步调用 Dubbo 服务。
+演示了 Go 和 Java 之间的异步互操作。
 
-## 运行步骤
+## 功能特性
 
-1. **启动服务端**
+- **Go 客户端和服务端**: 使用 `client.WithAsync()` 实现异步调用
+- **Java 客户端**: 使用 `CompletableFuture` API 实现异步调用
+- **Java 服务端**: 使用 `CompletableFuture` 实现异步服务
+- **互操作性**: Java 客户端可调用 Go 服务端,Go 客户端可调用 Java 服务端
+
+## 运行 Go 到 Go 示例
+
+1. **启动 Go 服务端**
 
    ```bash
    go run ./async/go-server/cmd/main.go
    ```
 
-2. **启动客户端**
+2. **启动 Go 客户端**(默认连接 Go 服务端)
+
+   ```bash
+   go run ./async/go-client/cmd/main.go
+   ```
+
+客户端会打印 "non-blocking before async callback resp: do something ... " 和 "test 
end" 日志,演示异步调用的非阻塞特性。
+
+## 运行 Java-Go 互操作示例
+
+演示**跨语言异步调用**:
+
+- **Go 客户端** → **Java 服务端**
+- **Java 客户端** → **Go 服务端**
+
+### 前置条件
+
+- Java 11 或更高版本
+- Maven 3.6+
+
+### 构建 Java 模块
+
+在 `async` 目录下执行:
+
+```bash
+mvn clean compile
+```
+
+### 测试:Go 客户端 → Java 服务端
+
+1. **修改 Go 客户端 URL**,在 `go-client/cmd/main.go` 中修改:
+
+   ```go

Review Comment:
   The documentation states that the Go client can be modified to connect to 
the Java server by changing the URL to "tri://127.0.0.1:50051", but the actual 
Go client code in go-client/cmd/main.go currently hardcodes 
"tri://127.0.0.1:20000". The README should clarify that this is the default 
configuration for Go-to-Go communication, and users need to manually change 
this line in the code to test Java interoperability as described.
   ```suggestion
   1. **修改 Go 客户端 URL**。Go 客户端默认配置为连接 Go 服务端(端口 `20000`),在 
`go-client/cmd/main.go` 中通常如下:
   
      ```go
      client.WithClientURL("tri://127.0.0.1:20000"),
      ```
   
      为了让 Go 客户端连接到 Java 服务端,请将上述行修改为:
   
      ```go
   ```



##########
async/pom.xml:
##########
@@ -0,0 +1,97 @@
+<?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.apache.dubbo.samples</groupId>
+    <artifactId>async-parent</artifactId>
+    <version>1.0.0</version>
+    <packaging>pom</packaging>
+    <name>async-parent</name>
+    <description>Parent POM for async RPC sample with Java-Go 
interoperability</description>
+
+    <modules>
+        <module>java-server</module>
+        <module>java-client</module>
+    </modules>
+
+    <properties>
+        <protobuf.version>3.21.7</protobuf.version>

Review Comment:
   The protobuf version specified is 3.21.7, but the generated Go code 
(user.pb.go line 20) indicates it was generated with protoc v6.33.1. This 
version mismatch between the Maven configuration and the actual protoc version 
used could lead to inconsistencies. Consider updating the protobuf.version 
property to match the version of protoc that will be used to generate the code, 
or document which version should be used for consistency across Go and Java 
code generation.
   ```suggestion
       <properties>
           <!-- Java-side protoc version used by protobuf-maven-plugin -->
           <protobuf.version>3.21.7</protobuf.version>
           <!-- Go-side protoc version used to generate user.pb.go (keep in 
sync with Go toolchain) -->
           <go.protoc.version>6.33.1</go.protoc.version>
   ```



##########
async/proto/user.proto:
##########
@@ -15,11 +15,20 @@
  * limitations under the License.
  */
 
+// Generate Go code from this proto file:
+// From the async directory, run:
+//   protoc --go_out=. --go_opt=paths=source_relative \
+//          --go-triple_out=. --go-triple_opt=paths=source_relative \
+//          ./proto/user.proto
+
 syntax = "proto3";
 
-package user;
+package org.apache.dubbo.samples.async.proto;

Review Comment:
   The proto package name has been changed from "user" to 
"org.apache.dubbo.samples.async.proto" for Java interoperability. While this is 
intentional for cross-language compatibility, it's important to note that this 
is a breaking change for any existing clients or servers using the old package 
name. The change appears in the generated service names and should be 
coordinated across all implementations.
   ```suggestion
   package user;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to