Skip to content

Commit 27ddd80

Browse files
committed
STDIN
1 feat(generic): add generic call sample for both Dubbo and Triple protocols 2 3 This PR refactors and enhances the generic call sample to demonstrate 4 both Dubbo protocol and Triple protocol generic calls between Go and Java. 5 6 ## Changes Overview 7 8 ### 1. Dual Protocol Support 9 | Protocol | Port | Group | Description | 10 |----------|-------|----------|----------------------------------| 11 | Dubbo | 20000 | `dubbo` | Traditional Dubbo binary protocol| 12 | Triple | 50052 | `triple` | HTTP/2 based Triple protocol | 13 14 ### 2. Direct Connection Mode 15 - Removed ZooKeeper dependency in favor of direct URL connection 16 - Simplifies local testing and CI/CD pipelines 17 - No external dependencies required to run the sample 18 19 ### 3. Project Structure Simplification 20 - Removed redundant nested directories (java-server/java-server → java-server) 21 - Added run.sh scripts for easy execution 22 23 ### 4. Comprehensive Test Suite 24 Added client_test.go with test cases covering: 25 - Dubbo Protocol Tests (6 cases) 26 - Triple Protocol Tests (13 cases) 27 - Benchmarks for both protocols 28 29 ### 5. Code Improvements 30 - Go server uses direct connection mode (no registry) 31 - user_provider.go Invoke method returns proper error for unknown methods 32 - Fixed QueryUsers parameter type to match Java array signature 33 34 ## Dependencies 35 This PR depends on apache/dubbo-go#3154 which adds `NewGenericService` API. 36 CI will pass after that PR is merged to main branch. 37 38 Signed-off-by: TsukiKage <chongyanx@163.com>
1 parent a6246b2 commit 27ddd80

7 files changed

Lines changed: 193 additions & 8 deletions

File tree

generic/go-client/cmd/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import (
3131

3232
hessian "github.com/apache/dubbo-go-hessian2"
3333

34-
"github.com/apache/dubbo-go-samples/generic/go-client/pkg"
35-
3634
"github.com/dubbogo/gost/log/logger"
3735
)
3836

37+
import (
38+
"github.com/apache/dubbo-go-samples/generic/go-client/pkg"
39+
)
40+
3941
const (
4042
DubboServerURL = "dubbo://127.0.0.1:20000"
4143
TripleServerURL = "tri://127.0.0.1:50052"

generic/go-client/cmd/client_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import (
3131
_ "dubbo.apache.org/dubbo-go/v3/imports"
3232

3333
hessian "github.com/apache/dubbo-go-hessian2"
34+
)
3435

36+
import (
3537
"github.com/apache/dubbo-go-samples/generic/go-client/pkg"
3638
)
3739

generic/go-server/cmd/server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import (
2727

2828
hessian "github.com/apache/dubbo-go-hessian2"
2929

30-
"github.com/apache/dubbo-go-samples/generic/go-server/pkg"
31-
3230
"github.com/dubbogo/gost/log/logger"
3331
)
3432

33+
import (
34+
"github.com/apache/dubbo-go-samples/generic/go-server/pkg"
35+
)
36+
3537
func main() {
3638
hessian.RegisterPOJO(&pkg.User{})
3739

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ require (
8585
github.com/hashicorp/hcl v1.0.0 // indirect
8686
github.com/hashicorp/vault/sdk v0.7.0 // indirect
8787
github.com/influxdata/tdigest v0.0.1 // indirect
88-
github.com/jinzhu/copier v0.3.5 // indirect
8988
github.com/jmespath/go-jmespath v0.4.0 // indirect
9089
github.com/json-iterator/go v1.1.12 // indirect
9190
github.com/k0kubun/pp v3.0.1+incompatible // indirect
@@ -173,7 +172,7 @@ require (
173172
)
174173

175174
replace (
176-
dubbo.apache.org/dubbo-go/v3 => ../dubbo-go
175+
dubbo.apache.org/dubbo-go/v3 => github.com/apache/dubbo-go/v3 v3.0.0-20260210015753-35ea886421f9
177176
go.opentelemetry.io/otel => go.opentelemetry.io/otel v1.26.0
178177
go.opentelemetry.io/otel/exporters/otlp/otlptrace => go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0
179178
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ github.com/apache/dubbo-go-hessian2 v1.9.1/go.mod h1:xQUjE7F8PX49nm80kChFvepA/Av
832832
github.com/apache/dubbo-go-hessian2 v1.9.3/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE=
833833
github.com/apache/dubbo-go-hessian2 v1.12.5 h1:19lJz2Md0EYF2bOtEvFqXEQRYvLz04GfsoocsBWlLWQ=
834834
github.com/apache/dubbo-go-hessian2 v1.12.5/go.mod h1:QP9Tc0w/B/mDopjusebo/c7GgEfl6Lz8jeuFg8JA6yw=
835+
github.com/apache/dubbo-go/v3 v3.0.0-20260210015753-35ea886421f9 h1:z9gt++7EVCWbMsCMedweVcjnK1OxmVq4Bj1DSnw92Hs=
836+
github.com/apache/dubbo-go/v3 v3.0.0-20260210015753-35ea886421f9/go.mod h1:3ggdIDIW72EmHD2hX9rfCULcKHlaRMSCXWUjAQ9exII=
835837
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
836838
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
837839
github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU=
@@ -1384,8 +1386,6 @@ github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj
13841386
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
13851387
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
13861388
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
1387-
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
1388-
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
13891389
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
13901390
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
13911391
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package integration
19+
20+
import (
21+
"context"
22+
"testing"
23+
"time"
24+
)
25+
26+
import (
27+
hessian "github.com/apache/dubbo-go-hessian2"
28+
29+
"github.com/stretchr/testify/assert"
30+
)
31+
32+
// User is the POJO type for generic call testing
33+
type User struct {
34+
ID string
35+
Name string
36+
Age int32
37+
Time time.Time
38+
}
39+
40+
func (u *User) JavaClassName() string {
41+
return "org.apache.dubbo.samples.User"
42+
}
43+
44+
func TestGenericGetUser1(t *testing.T) {
45+
result, err := genericService.Invoke(
46+
context.Background(),
47+
"GetUser1",
48+
[]string{"java.lang.String"},
49+
[]hessian.Object{"A003"},
50+
)
51+
assert.Nil(t, err)
52+
assert.NotNil(t, result)
53+
}
54+
55+
func TestGenericGetUser2(t *testing.T) {
56+
result, err := genericService.Invoke(
57+
context.Background(),
58+
"GetUser2",
59+
[]string{"java.lang.String", "java.lang.String"},
60+
[]hessian.Object{"A003", "lily"},
61+
)
62+
assert.Nil(t, err)
63+
assert.NotNil(t, result)
64+
}
65+
66+
func TestGenericGetUser3(t *testing.T) {
67+
result, err := genericService.Invoke(
68+
context.Background(),
69+
"GetUser3",
70+
[]string{"int"},
71+
[]hessian.Object{int32(1)},
72+
)
73+
assert.Nil(t, err)
74+
assert.NotNil(t, result)
75+
}
76+
77+
func TestGenericGetOneUser(t *testing.T) {
78+
result, err := genericService.Invoke(
79+
context.Background(),
80+
"GetOneUser",
81+
[]string{},
82+
[]hessian.Object{},
83+
)
84+
assert.Nil(t, err)
85+
assert.NotNil(t, result)
86+
}
87+
88+
func TestGenericGetUsers(t *testing.T) {
89+
result, err := genericService.Invoke(
90+
context.Background(),
91+
"GetUsers",
92+
[]string{"[Ljava.lang.String;"},
93+
[]hessian.Object{[]string{"001", "002", "003"}},
94+
)
95+
assert.Nil(t, err)
96+
assert.NotNil(t, result)
97+
}
98+
99+
func TestGenericQueryUser(t *testing.T) {
100+
testUser := &User{
101+
ID: "3213",
102+
Name: "panty",
103+
Age: 25,
104+
Time: time.Now(),
105+
}
106+
result, err := genericService.Invoke(
107+
context.Background(),
108+
"QueryUser",
109+
[]string{"org.apache.dubbo.samples.User"},
110+
[]hessian.Object{testUser},
111+
)
112+
assert.Nil(t, err)
113+
assert.NotNil(t, result)
114+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package integration
19+
20+
import (
21+
"os"
22+
"testing"
23+
)
24+
25+
import (
26+
"dubbo.apache.org/dubbo-go/v3"
27+
"dubbo.apache.org/dubbo-go/v3/client"
28+
"dubbo.apache.org/dubbo-go/v3/common/constant"
29+
"dubbo.apache.org/dubbo-go/v3/config/generic"
30+
_ "dubbo.apache.org/dubbo-go/v3/imports"
31+
32+
hessian "github.com/apache/dubbo-go-hessian2"
33+
)
34+
35+
var genericService *generic.GenericService
36+
37+
func TestMain(m *testing.M) {
38+
hessian.RegisterPOJO(&User{})
39+
40+
ins, err := dubbo.NewInstance(
41+
dubbo.WithName("generic-integration-test"),
42+
)
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
cli, err := ins.NewClient(
48+
client.WithClientProtocolTriple(),
49+
client.WithClientSerialization(constant.Hessian2Serialization),
50+
)
51+
if err != nil {
52+
panic(err)
53+
}
54+
55+
genericService, err = cli.NewGenericService(
56+
"org.apache.dubbo.samples.UserProvider",
57+
client.WithURL("tri://127.0.0.1:50052"),
58+
client.WithVersion("1.0.0"),
59+
client.WithGroup("triple"),
60+
)
61+
if err != nil {
62+
panic(err)
63+
}
64+
65+
os.Exit(m.Run())
66+
}

0 commit comments

Comments
 (0)