Copilot commented on code in PR #993: URL: https://github.com/apache/dubbo-go-samples/pull/993#discussion_r2605255655
########## h3/README_CN.md: ########## @@ -0,0 +1,152 @@ +# H3 (HTTP/3) for dubbo-go + +[English](README.md) | 中文 + +本示例演示了如何通过 Triple 协议在 dubbo-go 中使用 HTTP/3 协议支持。展示了使用 HTTP/3 为 Go 和 Java 服务之间的高性能通信提供支持,并使用 TLS 进行安全连接。 + +## 目录结构 + +- go-server/cmd/main.go - 服务端主程序,包含服务定义、处理器和 RPC 服务端,支持 HTTP/3 +- go-client/cmd/main.go - RPC 客户端,支持 HTTP/3 +- java-server/src/main/java/org/apache/dubbo/samples/h3/H3ServerApp.java - Java服务端,支持 HTTP/3 +- java-client/src/main/java/org/apache/dubbo/samples/h3/H3ClientApp.java - Java客户端,支持 HTTP/3 +- proto - API 的 protobuf 定义 +- x509 - 安全连接的 TLS 证书和密钥 + +## 主要特性 + +- **HTTP/3 协议支持**:通过 QUIC 传输实现更快、更可靠的连接 +- **跨语言互操作性**:演示 Go 和 Java 通过 HTTP/3 的互操作性 +- **TLS 加密**:使用客户端和服务器证书进行安全通信 +- **Triple 协议**:基于 Apache Dubbo 的 Triple 协议,启用 HTTP/3 支持 + +## 运行方法 + +### 前置条件 +1. 安装 `protoc` [version3][] + 参考[Protocol Buffer Compiler 安装][]。 + +2. 安装 `protoc-gen-go` 和 `protoc-gen-triple` + 以最新版本为例: + + ```shell + go install google.golang.org/protobuf/cmd/[email protected] + ``` + + 安装 protoc-gen-triple: + + ```shell + go install github.com/dubbogo/protoc-gen-go-triple/[email protected] + ``` + +3. 生成代码存根 + + 使用 protoc-gen-go 和 protoc-gen-go-triple 生成相关代码: + + ```shell + protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. --go-triple_opt=paths=source_relative ./proto/greet.proto + ``` + +4. 安装 `Maven` [Maven][] + +### 启动Golang服务端 +```shell +cd go-server/cmd +go run main.go +``` + +测试服务端是否正常: +```shell +curl -k \ + --header "Content-Type: application/json" \ + --data '{"name": "Dubbo"}' \ + https://localhost:20000/greet.GreetService/Greet +``` + +### 启动Golang客户端 +```shell +cd go-client/cmd +go run main.go +``` + +### 启动Java服务端 + +从根目录构建所有 Java 模块: +```shell +mvn clean compile +``` + +启动 Java 服务端: + +**在 Linux/Mac/Git Bash 上:** +```shell +cd java-server +mvn exec:java -Dexec.mainClass=org.apache.dubbo.samples.h3.H3ServerApp +``` + +**在 Windows PowerShell 上:** +```powershell +cd java-server +mvn exec:java "-Dexec.mainClass=org.apache.dubbo.samples.h3.H3ServerApp" +``` + +**或使用提供的脚本(Linux/Mac):** +```shell +cd java-server +./run.sh +``` + +测试服务端是否正常: +```shell +curl -k \ + --header "Content-Type: application/json" \ + --data '{"name": "Dubbo"}' \ + https://localhost:20000/greet.GreetService/Greet +``` + +### 启动Java客户端 + +启动 Java 客户端: + +**在 Linux/Mac/Git Bash 上:** +```shell +cd java-client +mvn exec:java -Dexec.mainClass=org.apache.dubbo.samples.h3.H3ClientApp +``` + +**在 Windows PowerShell 上:** +```powershell +cd java-client +mvn exec:java "-Dexec.mainClass=org.apache.dubbo.samples.h3.H3ClientApp" +``` + +**或使用提供的脚本(Linux/Mac):** +```shell +cd java-server Review Comment: The script references `java-server` directory but should reference `java-client` directory based on the file path. This copy-paste error means running this script from the java-client directory would navigate to the wrong location. ```suggestion cd java-client ``` ########## h3/go-client/cmd/main.go: ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "context" + "time" + + "dubbo.apache.org/dubbo-go/v3/client" + "dubbo.apache.org/dubbo-go/v3/protocol" + "dubbo.apache.org/dubbo-go/v3/protocol/triple" + + _ "dubbo.apache.org/dubbo-go/v3/imports" + + "dubbo.apache.org/dubbo-go/v3/tls" + "github.com/dubbogo/gost/log/logger" + + greet "github.com/apache/dubbo-go-samples/h3/proto" +) + +func main() { + logger.SetLoggerLevel("debug") + + cli, err := client.NewClient( + client.WithClientURL("127.0.0.1:20000"), + client.WithClientTLSOption( + tls.WithCACertFile("../../x509/server_ca_cert.pem"), + tls.WithCertFile("../../x509/server2_cert.pem"), + tls.WithKeyFile("../../x509/server2_key_pkcs8.pem"), + tls.WithServerName("dubbogo.test.example.com"), + ), + // Enable HTTP/3 support on client side + // This configures the client to use dualTransport which supports + // both HTTP/2 and HTTP/3 with Alt-Svc negotiation + client.WithClientProtocol(protocol.WithTriple(triple.Http3Enable())), + ) + if err != nil { + logger.Fatalf("failed to create client: %v", err) + return + } + + svc, err := greet.NewGreetService(cli) + if err != nil { + logger.Fatalf("failed to create greet service: %v", err) + } + + for i := 0; i < 3; i += 1 { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + + defer cancel() + + resp, err := svc.Greet(ctx, &greet.GreetRequest{Name: "Go Client"}) + if err != nil { + logger.Errorf("failed to greet: %v", err) + } + logger.Infof("Greet response: %s", resp.Greeting) + Review Comment: The `defer cancel()` is placed inside the loop, which means it will only execute after the function returns, not after each iteration. This causes context cancellations to accumulate and not be executed until the end of the main function. Move `defer cancel()` outside the loop or call `cancel()` explicitly at the end of each iteration to prevent context leaks. ```suggestion resp, err := svc.Greet(ctx, &greet.GreetRequest{Name: "Go Client"}) if err != nil { logger.Errorf("failed to greet: %v", err) } logger.Infof("Greet response: %s", resp.Greeting) cancel() ``` ########## h3/README.md: ########## @@ -0,0 +1,152 @@ +# H3 (HTTP/3) for dubbo-go + +English | [中文](README_CN.md) + +This example demonstrates how to use dubbo-go with HTTP/3 protocol support via the Triple protocol. It shows how to enable HTTP/3 for high-performance communication between Go and Java services using TLS for secure connections. + +## Contents + +- go-server/cmd/main.go - is the main definition of the service, handler and rpc server with HTTP/3 support +- go-client/cmd/main.go - is the rpc client with HTTP/3 support +- java-server/src/main/java/org/apache/dubbo/samples/h3/H3ServerApp.java - is the Java server with HTTP/3 support +- java-client/src/main/java/org/apache/dubbo/samples/h3/H3ClientApp.java - is the Java client with HTTP/3 support +- proto - contains the protobuf definition of the API +- x509 - contains TLS certificates and keys for secure connections + +## Key Features + +- **HTTP/3 Protocol Support**: Uses QUIC transport for faster, more reliable connections +- **Cross-Language Interoperability**: Demonstrates Go and Java interoperability with HTTP/3 +- **TLS Encryption**: Secure communication with client and server certificates +- **Triple Protocol**: Built on Apache Dubbo's Triple protocol with HTTP/3 enabled + +## How to run + +### Prerequisites +1. Install `protoc` [version3][] + Please refer to [Protocol Buffer Compiler Installation][]. + +2. Install `protoc-gen-go` and `protoc-gen-triple` + Install the version of your choice of protoc-gen-go. here use the latest version as example: + + ```shell + go install google.golang.org/protobuf/cmd/[email protected] + ``` + + Install the latest version of protoc-gen-triple: + + ```shell + go install github.com/dubbogo/protoc-gen-go-triple/[email protected] + ``` + +3. Generate stub code + + Generate related stub code with protoc-gen-go and protoc-gen-triple: + + ```shell + protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. --go-triple_opt=paths=source_relative ./proto/greet.proto + ``` + +4. Install `Maven` [Maven][] + +### Run Golang server +```shell +cd go-server/cmd +go run main.go +``` + +Test server works as expected: +```shell +curl -k \ + --header "Content-Type: application/json" \ + --data '{"name": "Dubbo"}' \ + https://localhost:20000/greet.GreetService/Greet +``` + +### Run Golang client +```shell +cd go-client/cmd +go run main.go +``` + +### Run Java server + +Build all Java modules from the root directory: +```shell +mvn clean compile +``` + +Run the Java server: + +**On Linux/Mac/Git Bash:** +```shell +cd java-server +mvn exec:java -Dexec.mainClass=org.apache.dubbo.samples.h3.H3ServerApp +``` + +**On Windows PowerShell:** +```powershell +cd java-server +mvn exec:java "-Dexec.mainClass=org.apache.dubbo.samples.h3.H3ServerApp" +``` + +**Or use the provided script (Linux/Mac):** +```shell +cd java-server +./run.sh +``` + +Test server works as expected: +```shell +curl -k \ + --header "Content-Type: application/json" \ + --data '{"name": "Dubbo"}' \ + https://localhost:20000/greet.GreetService/Greet +``` + +### Run Java client + +Run the Java client: + +**On Linux/Mac/Git Bash:** +```shell +cd java-client +mvn exec:java -Dexec.mainClass=org.apache.dubbo.samples.h3.H3ClientApp +``` + +**On Windows PowerShell:** +```powershell +cd java-client +mvn exec:java "-Dexec.mainClass=org.apache.dubbo.samples.h3.H3ClientApp" +``` + +**Or use the provided script (Linux/Mac):** +```shell +cd java-client +./run.sh Review Comment: The script references `java-server` directory but should reference `java-client` directory based on the context. This copy-paste error means the instructions would navigate to the wrong location. -- 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]
