You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/09/24 05:58:50 UTC
[dubbo-go-samples] branch config-enhance updated: feat(*): add
wrapper array class samples(waiting for dubbo-go-hessian upgrade) (#247)
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch config-enhance
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
The following commit(s) were added to refs/heads/config-enhance by this push:
new 6ed4505 feat(*): add wrapper array class samples(waiting for dubbo-go-hessian upgrade) (#247)
6ed4505 is described below
commit 6ed45056c26e5fca9c1cc40596b4af4eef825fe3
Author: Mulavar <97...@qq.com>
AuthorDate: Fri Sep 24 13:58:46 2021 +0800
feat(*): add wrapper array class samples(waiting for dubbo-go-hessian upgrade) (#247)
* feat(*): add wrapper array class samples
* add comment
* add license header
* use uint8 as Byte & use int16 as Short
* upgrade hessian version(pseudo version)
* enable rpc/dubbo integrate test
Co-authored-by: dongjianhui03 <do...@meituan.com>
---
go.mod | 2 +-
go.sum | 3 +-
rpc/dubbo/go-server/cmd/server.go | 1 +
rpc/dubbo/go-server/conf/dubbogo.yml | 3 +
.../{complex_service.go => complex_provider.go} | 0
.../go-server/pkg/wrapper_array_class_provider.go | 95 ++++++++++++++++++++++
.../src/main/java/org/apache/dubbo/Consumer.java | 24 ++++++
.../apache/dubbo/WrapperArrayClassProvider.java | 12 +++
8 files changed, 138 insertions(+), 2 deletions(-)
diff --git a/go.mod b/go.mod
index 41263ba..c50e084 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ require (
dubbo.apache.org/dubbo-go/v3 v3.0.0-rc2.0.20210915060211-8d727d630e0e
github.com/alibaba/sentinel-golang v1.0.2
github.com/apache/dubbo-getty v1.4.5
- github.com/apache/dubbo-go-hessian2 v1.9.2
+ github.com/apache/dubbo-go-hessian2 v1.9.4-0.20210917102639-74a8ece5f3cb
github.com/bwmarrin/snowflake v0.3.0
github.com/dubbogo/gost v1.11.16
github.com/dubbogo/net v0.0.4
diff --git a/go.sum b/go.sum
index bce78b0..08a2056 100644
--- a/go.sum
+++ b/go.sum
@@ -61,8 +61,9 @@ github.com/apache/dubbo-getty v1.4.3/go.mod h1:ansXgKxxyhCOiQL29nO5ce1MDcEKmCyZu
github.com/apache/dubbo-getty v1.4.5 h1:MptKbjC0n2Mo/8eFPwirSInH2BfdNG4IZch43PdNvIM=
github.com/apache/dubbo-getty v1.4.5/go.mod h1:mcDyiu7M/TVrYDyL8TxDemQkOdvEqqHSQ4jOuYejY1w=
github.com/apache/dubbo-go-hessian2 v1.9.1/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE=
-github.com/apache/dubbo-go-hessian2 v1.9.2 h1:XuI8KvENSfKiAhiCBS4RNihmQDoPNmGWKT3gTui0p9A=
github.com/apache/dubbo-go-hessian2 v1.9.2/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE=
+github.com/apache/dubbo-go-hessian2 v1.9.4-0.20210917102639-74a8ece5f3cb h1:EPlAQLAmvy/6hIEhNhDBTvVCbcNLXjherAunUEEcsJ0=
+github.com/apache/dubbo-go-hessian2 v1.9.4-0.20210917102639-74a8ece5f3cb/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
diff --git a/rpc/dubbo/go-server/cmd/server.go b/rpc/dubbo/go-server/cmd/server.go
index 54dc26c..cd0bbbe 100644
--- a/rpc/dubbo/go-server/cmd/server.go
+++ b/rpc/dubbo/go-server/cmd/server.go
@@ -50,6 +50,7 @@ func main() {
hessian.RegisterPOJO(&pkg.User{})
config.SetProviderService(&pkg.UserProvider{})
config.SetProviderService(&pkg.ComplexProvider{})
+ config.SetProviderService(&pkg.WrapperArrayClassProvider{})
// ------------
config.Load()
diff --git a/rpc/dubbo/go-server/conf/dubbogo.yml b/rpc/dubbo/go-server/conf/dubbogo.yml
index 8793c27..cd13362 100644
--- a/rpc/dubbo/go-server/conf/dubbogo.yml
+++ b/rpc/dubbo/go-server/conf/dubbogo.yml
@@ -27,3 +27,6 @@ dubbo:
ComplexProvider:
protocol: dubbo
interface: org.apache.dubbo.ComplexProvider
+ WrapperArrayClassProvider:
+ protocol: dubbo
+ interface: org.apache.dubbo.WrapperArrayClassProvider
diff --git a/rpc/dubbo/go-server/pkg/complex_service.go b/rpc/dubbo/go-server/pkg/complex_provider.go
similarity index 100%
rename from rpc/dubbo/go-server/pkg/complex_service.go
rename to rpc/dubbo/go-server/pkg/complex_provider.go
diff --git a/rpc/dubbo/go-server/pkg/wrapper_array_class_provider.go b/rpc/dubbo/go-server/pkg/wrapper_array_class_provider.go
new file mode 100644
index 0000000..0304f6c
--- /dev/null
+++ b/rpc/dubbo/go-server/pkg/wrapper_array_class_provider.go
@@ -0,0 +1,95 @@
+/*
+ * 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 pkg
+
+import (
+ "context"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+type WrapperArrayClassProvider struct {
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaIntegerArray(ctx context.Context, ia *hessian.IntegerArray) (*hessian.IntegerArray, error) {
+ logger.Info("InvokeWithJavaIntegerArray:", ia.Values)
+
+ newV := []int32{1, 2, 3}
+ ia.Values = newV
+ return ia, nil
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaBooleanArray(ctx context.Context, ba *hessian.BooleanArray) (*hessian.BooleanArray, error) {
+ logger.Info("InvokeWithJavaBooleanArray:", ba.Values)
+
+ newV := []bool{true, false, true}
+ ba.Values = newV
+ return ba, nil
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaShortArray(ctx context.Context, ba *hessian.ShortArray) (*hessian.ShortArray, error) {
+ logger.Info("InvokeWithJavaShortArray:", ba.Values)
+
+ newV := []int16{1, 2, 1000}
+ ba.Values = newV
+ return ba, nil
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaByteArray(ctx context.Context, ia *hessian.ByteArray) (*hessian.ByteArray, error) {
+ logger.Info("InvokeWithJavaByteArray:", ia.Values)
+
+ newV := []uint8{1, 2, 200}
+ ia.Values = newV
+ return ia, nil
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaFloatArray(ctx context.Context, ia *hessian.FloatArray) (*hessian.FloatArray, error) {
+ logger.Info("InvokeWithJavaFloatArray:", ia.Values)
+
+ newV := []float32{1, 2, 3}
+ ia.Values = newV
+ return ia, nil
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaDoubleArray(ctx context.Context, ia *hessian.DoubleArray) (*hessian.DoubleArray, error) {
+ logger.Info("InvokeWithJavaDoubleArray:", ia.Values)
+
+ newV := []float64{1, 2, 3}
+ ia.Values = newV
+ return ia, nil
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaLongArray(ctx context.Context, ia *hessian.LongArray) (*hessian.LongArray, error) {
+ logger.Info("InvokeWithJavaLongArray:", ia.Values)
+
+ newV := []int64{1, 2, 3}
+ ia.Values = newV
+ return ia, nil
+}
+
+func (u *WrapperArrayClassProvider) InvokeWithJavaCharacterArray(ctx context.Context, ia *hessian.CharacterArray) (*hessian.CharacterArray, error) {
+ logger.Info("InvokeWithJavaCharacterArray:", ia.Values)
+
+ newV := "hello world"
+ ia.Values = newV
+ return ia, nil
+}
diff --git a/rpc/dubbo/java-client/src/main/java/org/apache/dubbo/Consumer.java b/rpc/dubbo/java-client/src/main/java/org/apache/dubbo/Consumer.java
index 22c1e31..f48a86d 100644
--- a/rpc/dubbo/java-client/src/main/java/org/apache/dubbo/Consumer.java
+++ b/rpc/dubbo/java-client/src/main/java/org/apache/dubbo/Consumer.java
@@ -19,6 +19,7 @@ package org.apache.dubbo;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -44,6 +45,8 @@ public class Consumer {
start();
startComplexConsumerService();
+ // TODO when upgrade hessian version, remember to delete this comment
+ startWrapperArrayClassService();
}
// Start the entry function for consumer (Specified in the configuration file)
@@ -277,4 +280,25 @@ public class Consumer {
int rsp = complexProvider.InvokeWithMultiBasicData("str",new byte[]{1, 3, 4,6,7}, 32, true);
System.out.println("get multi basic rsp = "+ rsp);
}
+
+ public static void startWrapperArrayClassService() {
+ ReferenceConfig<WrapperArrayClassProvider> ref = new ReferenceConfig<>();
+ ref.setInterface(WrapperArrayClassProvider.class);
+ ref.setCheck(false);
+ ref.setProtocol(CommonConstants.DUBBO_PROTOCOL);
+ ref.setLazy(true);
+ ref.setTimeout(100000);
+ ref.setApplication(new ApplicationConfig("demo-consumer"));
+
+ ref.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
+ final WrapperArrayClassProvider wrapperArrayClassProvider = ref.get();
+ System.out.println("---InvokeWithJavaByteArray:" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaByteArray(new Byte[]{10, 100})));
+ System.out.println("---InvokeWithJavaCharacterArray" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaCharacterArray(new Character[]{'a', 'b', 'c'})));
+ System.out.println("---InvokeWithJavaShortArray" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaShortArray(new Short[]{1, 2, 3})));
+ System.out.println("---InvokeWithJavaIntegerArray" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaIntegerArray(new Integer[]{4, 5, 6})));
+ System.out.println("---InvokeWithJavaLongArray" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaLongArray(new Long[]{7L, 8L, 9000000000000L})));
+ System.out.println("---InvokeWithJavaFloatArray" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaFloatArray(new Float[]{1.2f, 2.3f, 3.0f})));
+ System.out.println("---InvokeWithJavaDoubleArray" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaDoubleArray(new Double[]{4.0, 5.1, 6.0})));
+ System.out.println("---InvokeWithJavaBooleanArray" + Arrays.toString(wrapperArrayClassProvider.InvokeWithJavaBooleanArray(new Boolean[]{true, false, true})));
+ }
}
diff --git a/rpc/dubbo/java-client/src/main/java/org/apache/dubbo/WrapperArrayClassProvider.java b/rpc/dubbo/java-client/src/main/java/org/apache/dubbo/WrapperArrayClassProvider.java
new file mode 100644
index 0000000..2b443d5
--- /dev/null
+++ b/rpc/dubbo/java-client/src/main/java/org/apache/dubbo/WrapperArrayClassProvider.java
@@ -0,0 +1,12 @@
+package org.apache.dubbo;
+
+public interface WrapperArrayClassProvider {
+ Integer[] InvokeWithJavaIntegerArray(Integer[] ia);
+ Byte[] InvokeWithJavaByteArray(Byte[] ba);
+ Short[] InvokeWithJavaShortArray(Short[] ia);
+ Long[] InvokeWithJavaLongArray(Long[] ia);
+ Character[] InvokeWithJavaCharacterArray(Character[] ia);
+ Float[] InvokeWithJavaFloatArray(Float[] ia);
+ Double[] InvokeWithJavaDoubleArray(Double[] ia);
+ Boolean[] InvokeWithJavaBooleanArray(Boolean[] ia);
+}