You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by jo...@apache.org on 2022/12/26 11:13:15 UTC

[shenyu] branch master updated: feat(dubbo): support dubbo3 tri protocol (#4286)

This is an automated email from the ASF dual-hosted git repository.

jooks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 3aba21812 feat(dubbo): support dubbo3 tri protocol (#4286)
3aba21812 is described below

commit 3aba21812cee1b43bd5a223f864536d8af6a248e
Author: fantiq <fa...@users.noreply.github.com>
AuthorDate: Mon Dec 26 19:13:09 2022 +0800

    feat(dubbo): support dubbo3 tri protocol (#4286)
    
    * feat(dubbo): support dubbo3 tri protocol
    
    * fix(dubbo): fix javadoc style
    
    * fix(dubbo): fix trailing comment style
    
    * fix(test): update test unit dependence version
    
    Co-authored-by: 范易龙 <fa...@bianfeng.com>
---
 .../dubbo/AlibabaDubboServiceBeanListener.java     |  1 +
 .../dubbo/ApacheDubboServiceBeanListener.java      |  1 +
 .../client/dubbo/common/dto/DubboRpcExt.java       | 40 +++++++++++++++-
 .../shenyu-integrated-test-combination/pom.xml     | 56 ++++++++++++++--------
 .../dubbo/cache/AlibabaDubboConfigCache.java       |  3 ++
 .../apache/dubbo/cache/ApacheDubboConfigCache.java |  3 ++
 .../plugin/dubbo/common/cache/DubboParam.java      | 21 ++++++++
 7 files changed, 104 insertions(+), 21 deletions(-)

diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java
index 95aa3c4b4..fd41f872a 100644
--- a/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java
+++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java
@@ -172,6 +172,7 @@ public class AlibabaDubboServiceBeanListener extends AbstractContextRefreshedEve
 
     private String buildRpcExt(final ServiceBean<?> serviceBean) {
         DubboRpcExt build = DubboRpcExt.builder()
+                .protocol(StringUtils.isNotEmpty(serviceBean.getProtocol().getName()) ? serviceBean.getProtocol().getName() : "")
                 .group(StringUtils.isNotEmpty(serviceBean.getGroup()) ? serviceBean.getGroup() : "")
                 .version(StringUtils.isNotEmpty(serviceBean.getVersion()) ? serviceBean.getVersion() : "")
                 .loadbalance(StringUtils.isNotEmpty(serviceBean.getLoadbalance()) ? serviceBean.getLoadbalance() : Constants.DEFAULT_LOADBALANCE)
diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
index e5879dcff..d5efaceb3 100644
--- a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
+++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
@@ -174,6 +174,7 @@ public class ApacheDubboServiceBeanListener extends AbstractContextRefreshedEven
     
     private String buildRpcExt(final ServiceBean<?> serviceBean) {
         DubboRpcExt build = DubboRpcExt.builder()
+                .protocol(StringUtils.isNotEmpty(serviceBean.getProtocol().getName()) ? serviceBean.getProtocol().getName() : "")
                 .group(StringUtils.isNotEmpty(serviceBean.getGroup()) ? serviceBean.getGroup() : "")
                 .version(StringUtils.isNotEmpty(serviceBean.getVersion()) ? serviceBean.getVersion() : "")
                 .loadbalance(StringUtils.isNotEmpty(serviceBean.getLoadbalance()) ? serviceBean.getLoadbalance() : CommonConstants.DEFAULT_LOADBALANCE)
diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/dto/DubboRpcExt.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/dto/DubboRpcExt.java
index bec5bae80..76774fbdd 100644
--- a/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/dto/DubboRpcExt.java
+++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/dto/DubboRpcExt.java
@@ -42,6 +42,8 @@ public class DubboRpcExt implements Serializable {
 
     private String cluster;
 
+    private String protocol;
+
     /**
      * constructor without parameter.
      */
@@ -59,6 +61,7 @@ public class DubboRpcExt implements Serializable {
      * @param url url
      * @param sent sent
      * @param cluster cluster
+     * @param protocol protocol
      */
     public DubboRpcExt(final String group,
                        final String version,
@@ -67,7 +70,8 @@ public class DubboRpcExt implements Serializable {
                        final Integer timeout,
                        final String url,
                        final Boolean sent,
-                       final String cluster) {
+                       final String cluster,
+                       final String protocol) {
         this.group = group;
         this.version = version;
         this.loadbalance = loadbalance;
@@ -76,6 +80,7 @@ public class DubboRpcExt implements Serializable {
         this.url = url;
         this.sent = sent;
         this.cluster = cluster;
+        this.protocol = protocol;
     }
 
     /**
@@ -222,6 +227,24 @@ public class DubboRpcExt implements Serializable {
         this.cluster = cluster;
     }
 
+    /**
+     * get cluster.
+     *
+     * @return protocol
+     */
+    public String getProtocol() {
+        return protocol;
+    }
+
+    /**
+     * set protocol.
+     *
+     * @param protocol protocol
+     */
+    public void setProtocol(final String protocol) {
+        this.protocol = protocol;
+    }
+
     @Override
     public String toString() {
         return "DubboRpcExt{"
@@ -233,6 +256,7 @@ public class DubboRpcExt implements Serializable {
                 + ", url='" + url + '\''
                 + ", sent=" + sent
                 + ", cluster='" + cluster + '\''
+                + ", protocol='" + protocol + '\''
                 + '}';
     }
 
@@ -266,6 +290,8 @@ public class DubboRpcExt implements Serializable {
 
         private String cluster;
 
+        private String protocol;
+
         /**
          * constructor without parameter.
          */
@@ -360,6 +386,17 @@ public class DubboRpcExt implements Serializable {
             return this;
         }
 
+        /**
+         * set protocol.
+         *
+         * @param protocol protocol
+         * @return Builder
+         */
+        public Builder protocol(final String protocol) {
+            this.protocol = protocol;
+            return this;
+        }
+
         /**
          * build DubboRpcExt.
          *
@@ -375,6 +412,7 @@ public class DubboRpcExt implements Serializable {
             dubboRpcExt.setUrl(url);
             dubboRpcExt.setSent(sent);
             dubboRpcExt.setCluster(cluster);
+            dubboRpcExt.setProtocol(protocol);
             return dubboRpcExt;
         }
     }
diff --git a/shenyu-integrated-test/shenyu-integrated-test-combination/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-combination/pom.xml
index da1c02c91..2bea508b5 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-combination/pom.xml
+++ b/shenyu-integrated-test/shenyu-integrated-test-combination/pom.xml
@@ -58,6 +58,37 @@
         </dependency>
 
         <!--shenyu apache dubbo plugin start-->
+        <!--<dependency>-->
+        <!--    <groupId>org.apache.shenyu</groupId>-->
+        <!--    <artifactId>shenyu-spring-boot-starter-plugin-apache-dubbo</artifactId>-->
+        <!--    <version>${project.version}</version>-->
+        <!--</dependency>-->
+        <!--<dependency>-->
+        <!--    <groupId>org.apache.dubbo</groupId>-->
+        <!--    <artifactId>dubbo</artifactId>-->
+        <!--    <version>${apache.dubbo.version}</version>-->
+        <!--</dependency>-->
+        <!--<dependency>-->
+        <!--    <groupId>org.apache.curator</groupId>-->
+        <!--    <artifactId>curator-client</artifactId>-->
+        <!--    <version>${curator.version}</version>-->
+        <!--    <exclusions>-->
+        <!--        <exclusion>-->
+        <!--            <artifactId>log4j</artifactId>-->
+        <!--            <groupId>log4j</groupId>-->
+        <!--        </exclusion>-->
+        <!--    </exclusions>-->
+        <!--</dependency>-->
+        <!--<dependency>-->
+        <!--    <groupId>org.apache.curator</groupId>-->
+        <!--    <artifactId>curator-framework</artifactId>-->
+        <!--    <version>${curator.version}</version>-->
+        <!--</dependency>-->
+        <!--<dependency>-->
+        <!--    <groupId>org.apache.curator</groupId>-->
+        <!--    <artifactId>curator-recipes</artifactId>-->
+        <!--    <version>${curator.version}</version>-->
+        <!--</dependency>-->
         <dependency>
             <groupId>org.apache.shenyu</groupId>
             <artifactId>shenyu-spring-boot-starter-plugin-apache-dubbo</artifactId>
@@ -66,28 +97,13 @@
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo</artifactId>
-            <version>${apache.dubbo.version}</version>
+            <version>3.1.1</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-client</artifactId>
-            <version>${curator.version}</version>
-            <exclusions>
-                <exclusion>
-                    <artifactId>log4j</artifactId>
-                    <groupId>log4j</groupId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-framework</artifactId>
-            <version>${curator.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-recipes</artifactId>
-            <version>${curator.version}</version>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <version>3.1.1</version>
+            <type>pom</type>
         </dependency>
         <!--shenyu apache dubbo plugin end-->
 
diff --git a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCache.java b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCache.java
index 5d1a5e46b..7ef449198 100644
--- a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCache.java
+++ b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCache.java
@@ -156,6 +156,7 @@ public final class AlibabaDubboConfigCache extends DubboConfigCache {
         reference.setRegistry(registryConfig);
         reference.setConsumer(consumerConfig);
         reference.setInterface(metaData.getServiceName());
+        // default protocol is dubbo
         reference.setProtocol("dubbo");
         reference.setAsync(true);
         reference.setCheck(false);
@@ -180,6 +181,8 @@ public final class AlibabaDubboConfigCache extends DubboConfigCache {
             if (StringUtils.isNoneBlank(dubboParam.getCluster())) {
                 reference.setCluster(dubboParam.getCluster());
             }
+            // set dubbo sub protocol
+            Optional.ofNullable(dubboParam.getProtocol()).ifPresent(reference::setProtocol);
             Optional.ofNullable(dubboParam.getTimeout()).ifPresent(reference::setTimeout);
             Optional.ofNullable(dubboParam.getRetries()).ifPresent(reference::setRetries);
             Optional.ofNullable(dubboParam.getSent()).ifPresent(reference::setSent);
diff --git a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java
index 4822da3dd..97aacc717 100644
--- a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java
+++ b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java
@@ -199,6 +199,7 @@ public final class ApacheDubboConfigCache extends DubboConfigCache {
         reference.setRegistry(registryConfig);
         reference.setConsumer(consumerConfig);
         reference.setInterface(metaData.getServiceName());
+        // default protocol is dubbo
         reference.setProtocol("dubbo");
         reference.setCheck(false);
         reference.setLoadbalance("gray");
@@ -222,6 +223,8 @@ public final class ApacheDubboConfigCache extends DubboConfigCache {
             if (StringUtils.isNoneBlank(dubboParam.getCluster())) {
                 reference.setCluster(dubboParam.getCluster());
             }
+            // set dubbo sub protocol
+            Optional.ofNullable(dubboParam.getProtocol()).ifPresent(reference::setProtocol);
             Optional.ofNullable(dubboParam.getTimeout()).ifPresent(reference::setTimeout);
             Optional.ofNullable(dubboParam.getRetries()).ifPresent(reference::setRetries);
             Optional.ofNullable(dubboParam.getSent()).ifPresent(reference::setSent);
diff --git a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboParam.java b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboParam.java
index 2362049b2..d609310a5 100644
--- a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboParam.java
+++ b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboParam.java
@@ -62,6 +62,11 @@ public class DubboParam {
      */
     private String cluster;
 
+    /**
+     * the protocol (dubbo3 sub protocol).
+     */
+    private String protocol;
+
     /**
      * Gets group.
      *
@@ -205,4 +210,20 @@ public class DubboParam {
     public void setCluster(final String cluster) {
         this.cluster = cluster;
     }
+
+    /**
+     * Gets protocol.
+     * @return the protocol
+     */
+    public String getProtocol() {
+        return protocol;
+    }
+
+    /**
+     * Sets protocol.
+     * @param protocol the protocol
+     */
+    public void setProtocol(final String protocol) {
+        this.protocol = protocol;
+    }
 }