Skip to content

Conversation

@Tsukikage7
Copy link

@Tsukikage7 Tsukikage7 commented Jan 6, 2026

What this PR does

This PR refactors and enhances the generic call sample to demonstrate both Dubbo protocol and Triple protocol generic calls between Go and Java.

Dependencies

This PR depends on apache/dubbo-go#3154 which adds NewGenericService API.
CI will pass after that PR is merged to main branch.

Background

The existing generic sample only demonstrated Dubbo protocol generic call. With the new Triple protocol generic call support in dubbo-go (see apache/dubbo-go#3154), this sample needs to be updated to showcase both protocols.

Changes Overview

1. Dual Protocol Support

The sample now demonstrates generic call on both protocols:

Protocol Port Group Description
Dubbo 20000 dubbo Traditional Dubbo binary protocol
Triple 50052 triple HTTP/2 based Triple protocol

2. Java Server Enhancement

Before: Single protocol, ZooKeeper dependency
After: Dual protocol, direct connection mode

// ApiProvider.java - Now exposes both protocols
public class ApiProvider {
    private static final int DUBBO_PORT = 20000;
    private static final int TRIPLE_PORT = 50052;

    public static void main(String[] args) {
        // Dubbo protocol service (group=dubbo)
        ServiceConfig<UserProvider> dubboService = new ServiceConfig<>();
        dubboService.setGroup("dubbo");
        dubboService.setProtocol(new ProtocolConfig("dubbo", DUBBO_PORT));

        // Triple protocol service (group=triple)
        ServiceConfig<UserProvider> tripleService = new ServiceConfig<>();
        tripleService.setGroup("triple");
        tripleService.setProtocol(new ProtocolConfig("tri", TRIPLE_PORT));

        // Bootstrap both services...
    }
}

3. Go Client Enhancement

Before: Only Dubbo protocol test
After: Tests both Dubbo and Triple protocols using new GenericService API

func main() {
    // Test Dubbo protocol generic call
    logger.Info("=== Testing Dubbo Protocol Generic Call ===")
    testDubboProtocol(ins)

    // Test Triple protocol generic call
    logger.Info("=== Testing Triple Protocol Generic Call ===")
    testTripleProtocol(ins)
}

func testDubboProtocol(ins *dubbo.Instance) {
    cli, _ := ins.NewClient(
        client.WithClientProtocolDubbo(),
        client.WithClientSerialization(constant.Hessian2Serialization),
    )
    // Use NewGenericService for traditional Dubbo-style generic call API
    genericService, _ := cli.NewGenericService(UserProvider,
        client.WithURL("dubbo://127.0.0.1:20000"),
        client.WithVersion("1.0.0"),
        client.WithGroup("dubbo"),
    )
    runGenericTests(genericService, "Dubbo")
}

func testTripleProtocol(ins *dubbo.Instance) {
    cli, _ := ins.NewClient(
        client.WithClientProtocolTriple(),
        client.WithClientSerialization(constant.Hessian2Serialization),
    )
    // Use NewGenericService for traditional Dubbo-style generic call API
    genericService, _ := cli.NewGenericService(UserProvider,
        client.WithURL("tri://127.0.0.1:50052"),
        client.WithVersion("1.0.0"),
        client.WithGroup("triple"),
    )
    runGenericTests(genericService, "Triple")
}

// GenericService.Invoke provides traditional $invoke style API
func runGenericTests(svc *generic.GenericService, protocol string) {
    // GetUser1(String)
    result, _ := svc.Invoke(ctx, "GetUser1",
        []string{"java.lang.String"},
        []hessian.Object{"A003"})
    logger.Infof("[%s] GetUser1 res: %+v", protocol, result)

    // QueryUser(User) - POJO parameter
    result, _ = svc.Invoke(ctx, "QueryUser",
        []string{"org.apache.dubbo.samples.User"},
        []hessian.Object{&pkg.User{ID: "001", Name: "test", Age: 25}})
    logger.Infof("[%s] QueryUser res: %+v", protocol, result)
}

4. Comprehensive Test Suite

Added client_test.go with 19 test cases:

Dubbo Protocol Tests (6 cases):

  • TestDubboGenericCall_StringArg
  • TestDubboGenericCall_MultipleArgs
  • TestDubboGenericCall_IntArg
  • TestDubboGenericCall_NoArgs
  • TestDubboGenericCall_ArrayArg
  • TestDubboGenericCall_POJOArg

Triple Protocol Tests (13 cases):

  • TestTripleGenericCall_StringArg
  • TestTripleGenericCall_MultipleArgs
  • TestTripleGenericCall_IntArg
  • TestTripleGenericCall_NoArgs
  • TestTripleGenericCall_ArrayArg
  • TestTripleGenericCall_POJOArg
  • TestTripleGenericCall_POJOArrayArg
  • TestTripleGenericCall_MapResult
  • TestTripleGenericCall_ListResult
  • TestTripleGenericCall_EmptyArrayArg
  • TestTripleGenericCall_NonExistentMethod
  • TestTripleGenericCall_WithTimeout
  • TestTripleGenericCall_WithCancelledContext

Benchmarks:

  • BenchmarkDubboGenericCall
  • BenchmarkTripleGenericCall

5. Project Structure Simplification

Before (nested directories):

generic/
├── java-server/
│   └── java-server/     # Redundant nesting
│       ├── pom.xml
│       └── src/
├── java-client/
│   └── java-client/     # Redundant nesting
│       ├── pom.xml
│       └── src/

After (flat structure):

generic/
├── java-server/
│   ├── pom.xml
│   ├── run.sh
│   └── src/
├── java-client/
│   ├── pom.xml
│   ├── run.sh
│   └── src/
├── go-server/
│   └── cmd/
├── go-client/
│   └── cmd/
│       ├── client.go
│       └── client_test.go

6. Removed ZooKeeper Dependency

  • Changed from registry-based service discovery to direct URL connection
  • Simplifies local testing and CI/CD pipelines
  • No external dependencies required to run the sample

Files Changed

File Change Type Description
generic/java-server/src/.../ApiProvider.java Modified Dual protocol support
generic/java-client/src/.../ApiTripleConsumer.java Added Triple protocol consumer
generic/go-client/cmd/client.go Modified Both protocol tests
generic/go-client/cmd/client_test.go Added 19 test cases + benchmarks
generic/go-server/cmd/server.go Modified Enhanced server
generic/go-server/pkg/user_provider.go Modified Cleaner implementation
generic/java-server/run.sh Added Easy run script
generic/java-client/run.sh Added Easy run script
generic/README.md Modified Updated documentation
generic/README_zh.md Modified Updated Chinese documentation
generic/java-*/java-*/ Deleted Removed redundant nesting
generic/build/test.sh Deleted Obsolete test script

How to Test

1. Start Java Server

cd generic/java-server
./run.sh

2. Run Go Client Tests

cd generic/go-client/cmd
go test -v

3. Or Run Go Client Manually

cd generic/go-client/cmd
go run client.go

Test Results

=== Testing Dubbo Protocol Generic Call ===
[Dubbo] GetUser1(userId string) res: map[age:48 class:org.apache.dubbo.samples.User ...]
[Dubbo] GetUser2(userId string, name string) res: map[age:48 ...]
[Dubbo] GetUser3(userCode int) res: map[age:48 ...]
[Dubbo] GetUser4(userCode int, name string) res: map[age:48 ...]
[Dubbo] GetOneUser() res: map[age:48 ...]
[Dubbo] GetUsers(userIdList []string) res: [map[age:48 ...] map[age:48 ...] ...]
[Dubbo] GetUsersMap(userIdList []string) res: map[001:map[age:48 ...] ...]
[Dubbo] QueryAll() res: [map[age:48 ...] map[age:48 ...]]
[Dubbo] QueryUser(user *User) res: map[age:25 ...]
[Dubbo] QueryUsers(users []*User) res: [map[age:24 ...] map[age:21 ...]]

=== Testing Triple Protocol Generic Call ===
[Triple] GetUser1(userId string) res: map[age:48 ...]
[Triple] GetUser2(userId string, name string) res: map[age:48 ...]
[Triple] GetUser3(userCode int) res: map[age:48 ...]
[Triple] GetUser4(userCode int, name string) res: map[age:48 ...]
[Triple] GetOneUser() res: map[age:48 ...]
[Triple] GetUsers(userIdList []string) res: [map[age:48 ...] ...]
[Triple] GetUsersMap(userIdList []string) res: map[001:map[age:48 ...] ...]
[Triple] QueryAll() res: [map[age:48 ...] map[age:48 ...]]
[Triple] QueryUser(user *User) res: map[age:25 ...]
[Triple] QueryUsers(users []*User) res: [map[age:24 ...] map[age:21 ...]]

All generic call tests completed

Related PRs


Signed-off-by: TsukiKage [email protected]

@Tsukikage7 Tsukikage7 force-pushed the test/generic-interop-enhanced branch 4 times, most recently from 9babfa4 to da7f82d Compare January 6, 2026 04:03
@Tsukikage7
Copy link
Author

⚠️ CI Failure Note

The golangci-lint check fails because this PR uses NewGenericService API which is added in apache/dubbo-go#3154.

CI will pass after apache/dubbo-go#3154 is merged to main branch.

Dependency chain:

  1. feat(triple): support generic call for Triple protocol dubbo-go#3154 (adds NewGenericService API) - merge first
  2. This PR (uses the new API) - merge after

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the generic call sample to demonstrate both Dubbo and Triple protocol generic calls between Go and Java. The refactoring includes dual protocol support, project structure simplification, and a comprehensive test suite with 19 test cases.

Changes:

  • Added dual protocol support (Dubbo on port 20000 and Triple on port 50052) with separate service groups
  • Refactored project structure by removing redundant nested directories (java-server/java-server → java-server)
  • Added comprehensive test coverage with 19 test cases and 2 benchmarks for generic calls
  • Changed QueryUsers signature from List to User[] for consistency

Reviewed changes

Copilot reviewed 30 out of 38 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
go.mod Added local replace directive for dubbo-go dependency (temporary)
generic/java-server/src/main/java/org/apache/dubbo/samples/ApiProvider.java New dual protocol server implementation
generic/java-server/src/main/java/org/apache/dubbo/samples/User.java Added User POJO class
generic/java-server/src/main/java/org/apache/dubbo/samples/Gender.java Added Gender enum
generic/java-server/src/main/java/org/apache/dubbo/samples/UserProvider.java Changed QueryUsers from List to array
generic/java-server/src/main/java/org/apache/dubbo/samples/UserProviderImpl.java Updated QueryUsers implementation
generic/java-client/src/main/java/org/apache/dubbo/samples/ApiTripleConsumer.java New Triple protocol consumer
generic/java-client/pom.xml New client pom configuration
generic/go-server/cmd/server.go Simplified server implementation
generic/go-server/pkg/user_provider.go Added Invoke method for generic calls
generic/go-client/cmd/client.go Refactored to test both protocols
generic/go-client/cmd/client_test.go Added comprehensive test suite
generic/README.md Updated documentation
generic/README_zh.md Updated Chinese documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)

replace (
dubbo.apache.org/dubbo-go/v3 => ../dubbo-go
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local replace directive points to a relative path '../dubbo-go' which is a temporary development dependency. This should be removed before merging to production. The PR description mentions this depends on apache/dubbo-go#3154, so this replace directive should only be present during development/testing and removed once that PR is merged.

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +23
启动 ZooKeeper:

- Docker 和 Docker Compose 用于运行 ZooKeeper 注册中心
- Go 1.23+ 用于 Dubbo-Go 示例
- Java 8+ 和 Maven 用于 Dubbo Java 示例
```bash
docker run -d --name zookeeper -p 2181:2181 zookeeper:3.8
```
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Chinese README also includes ZooKeeper setup instructions in the Prerequisites section, which is inconsistent with the direct connection approach described in the PR. This section should be updated to match the removal of ZooKeeper dependency.

Copilot uses AI. Check for mistakes.
@AlexStocks
Copy link
Contributor

Please fix the ci failure and review the copilot's comment.

@Alanxtl
Copy link
Contributor

Alanxtl commented Jan 15, 2026

这个ci fail只能等dubbogo发新tag才能解决

)

replace (
dubbo.apache.org/dubbo-go/v3 => ../dubbo-go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个replace不要上传

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我等一下改一下,我把copliot提的那些问题修复一下吧

@Tsukikage7 Tsukikage7 force-pushed the test/generic-interop-enhanced branch 3 times, most recently from 5c643ce to 5c4a941 Compare January 15, 2026 04:36
…ocols

This PR refactors and enhances the generic call sample to demonstrate
both Dubbo protocol and Triple protocol generic calls between Go and Java.

## Changes Overview

### 1. Dual Protocol Support
| Protocol | Port  | Group    | Description                      |
|----------|-------|----------|----------------------------------|
| Dubbo    | 20000 | `dubbo`  | Traditional Dubbo binary protocol|
| Triple   | 50052 | `triple` | HTTP/2 based Triple protocol     |

### 2. Direct Connection Mode
- Removed ZooKeeper dependency in favor of direct URL connection
- Simplifies local testing and CI/CD pipelines
- No external dependencies required to run the sample

### 3. Project Structure Simplification
- Removed redundant nested directories (java-server/java-server → java-server)
- Added run.sh scripts for easy execution

### 4. Comprehensive Test Suite
Added client_test.go with test cases covering:
- Dubbo Protocol Tests (6 cases)
- Triple Protocol Tests (13 cases)
- Benchmarks for both protocols

### 5. Code Improvements
- Go server uses direct connection mode (no registry)
- user_provider.go Invoke method returns proper error for unknown methods
- Fixed QueryUsers parameter type to match Java array signature

## Dependencies
This PR depends on apache/dubbo-go#3154 which adds `NewGenericService` API.
CI will pass after that PR is merged to main branch.

Signed-off-by: TsukiKage <[email protected]>
@Tsukikage7 Tsukikage7 force-pushed the test/generic-interop-enhanced branch from 5c4a941 to 5d068dd Compare January 15, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants