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

hefengen 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 a467f25a5 Supports the motan protocol (#5003)
a467f25a5 is described below

commit a467f25a5cf8c99e991a241613654323d464c5ec
Author: coderDylan <[email protected]>
AuthorDate: Wed Aug 16 08:45:31 2023 +0800

    Supports the motan protocol (#5003)
    
    * Multi-protocol support for motan rpc plugin
    
    * fixed for checkstyle
    
    * fixed ci
    
    * fixed ci
    
    ---------
    
    Co-authored-by: lang_ding <[email protected]>
    Co-authored-by: moremind <[email protected]>
---
 .../client/motan/MotanServiceEventListener.java    | 19 +++++++++++++++---
 .../client/motan/common/dto/MotanRpcExt.java       | 23 +++++++++++++++++++++-
 .../src/main/resources/application.yml             |  3 ++-
 .../plugin/motan/cache/ApplicationConfigCache.java | 17 ++++++++++++++++
 .../plugin/motan/proxy/MotanProxyService.java      |  7 ++++++-
 .../motan/ShenyuMotanClientConfiguration.java      | 22 ++++++++++++++++++---
 .../client/motan/property/ShenyuMotanConfig.java   | 10 ++++++++--
 7 files changed, 90 insertions(+), 11 deletions(-)

diff --git 
a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java
 
b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java
index 7a0816e09..62dd42e65 100644
--- 
a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java
+++ 
b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java
@@ -144,6 +144,7 @@ public class MotanServiceEventListener extends 
AbstractContextRefreshedEventList
         } else {
             serviceName = service.interfaceClass().getName();
         }
+        String protocol = StringUtils.isNotEmpty(service.protocol()) ? 
service.protocol() : (getProtocolFromExport());
         return MetaDataRegisterDTO.builder()
                 .appName(this.getAppName())
                 .serviceName(serviceName)
@@ -156,7 +157,7 @@ public class MotanServiceEventListener extends 
AbstractContextRefreshedEventList
                 .pathDesc(desc)
                 .parameterTypes(parameterTypes)
                 .rpcType(RpcTypeEnum.MOTAN.getName())
-                .rpcExt(buildRpcExt(method, timeout))
+                .rpcExt(buildRpcExt(method, timeout, protocol))
                 .enabled(shenyuMotanClient.enabled())
                 .build();
     }
@@ -193,10 +194,22 @@ public class MotanServiceEventListener extends 
AbstractContextRefreshedEventList
         return new MotanRpcExt.RpcExt(method.getName(), params);
     }
 
-    private String buildRpcExt(final Method method, final Integer timeout) {
+    private String buildRpcExt(final Method method, final Integer timeout, 
final String rpcProtocol) {
         List<MotanRpcExt.RpcExt> list = new ArrayList<>();
         list.add(buildRpcExt(method));
-        MotanRpcExt buildList = new MotanRpcExt(list, group, timeout);
+        MotanRpcExt buildList = new MotanRpcExt(list, group, timeout, 
rpcProtocol);
         return GsonUtils.getInstance().toJson(buildList);
     }
+
+    /**
+     * Get the protocol from BasicServiceConfigBean export.
+     * @return rpc protocol
+     */
+    private String getProtocolFromExport() {
+        String export = Optional.ofNullable(((BasicServiceConfigBean) 
applicationContext.getBean(BASE_SERVICE_CONFIG)).getExport()).orElse("");
+        if (StringUtils.isNotEmpty(export) && export.contains(":")) {
+            return export.split(":")[0];
+        }
+        return "motan2";
+    }
 }
diff --git 
a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/dto/MotanRpcExt.java
 
b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/dto/MotanRpcExt.java
index 48d83aed8..44a927c51 100644
--- 
a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/dto/MotanRpcExt.java
+++ 
b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/dto/MotanRpcExt.java
@@ -36,6 +36,8 @@ public class MotanRpcExt {
 
     private Integer timeout;
 
+    private String rpcProtocol;
+
     /**
      * constructor without params.
      */
@@ -48,11 +50,13 @@ public class MotanRpcExt {
      * @param methodInfo methodInfo
      * @param group group
      * @param timeout timeout
+     * @param rpcProtocol rpcProtocol
      */
-    public MotanRpcExt(final List<RpcExt> methodInfo, final String group, 
final Integer timeout) {
+    public MotanRpcExt(final List<RpcExt> methodInfo, final String group, 
final Integer timeout, final String rpcProtocol) {
         this.methodInfo = methodInfo;
         this.group = group;
         this.timeout = timeout;
+        this.rpcProtocol = rpcProtocol;
     }
 
     /**
@@ -107,12 +111,29 @@ public class MotanRpcExt {
         this.timeout = timeout;
     }
 
+    /**
+     * get rpc protocol.
+     * @return rpcProtocol
+     */
+    public String getRpcProtocol() {
+        return rpcProtocol;
+    }
+
+    /**
+     * set rpcProtocol.
+     * @param rpcProtocol rpc protocol
+     */
+    public void setRpcProtocol(final String rpcProtocol) {
+        this.rpcProtocol = rpcProtocol;
+    }
+
     @Override
     public String toString() {
         return "MotanRpcExt{"
                 + "methodInfo=" + methodInfo
                 + ", group='" + group + '\''
                 + ", timeout='" + timeout + '\''
+                + ", rpcProtocol='" + rpcProtocol + '\''
                 + '}';
     }
 
diff --git 
a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/resources/application.yml
 
b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/resources/application.yml
index d9f2b31ed..63bbcd316 100644
--- 
a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/resources/application.yml
+++ 
b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/resources/application.yml
@@ -40,7 +40,8 @@ shenyu:
       package-path: org.apache.shenyu.examples.motan.service
       basicServiceConfig:
         exportPort: 8002
-
+      protocol:
+        name: motan2
 motan:
   registry:
     protocol: zk
diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/cache/ApplicationConfigCache.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/cache/ApplicationConfigCache.java
index 42b824c27..eaacca46c 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/cache/ApplicationConfigCache.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/cache/ApplicationConfigCache.java
@@ -188,6 +188,9 @@ public final class ApplicationConfigCache {
         reference.setVersion("1.0");
         
reference.setRequestTimeout(Optional.ofNullable(motanParamExtInfo.getTimeout()).orElse(1000));
         reference.setRegistry(registryConfig);
+        if (StringUtils.isNotEmpty(motanParamExtInfo.getRpcProtocol())) {
+            protocolConfig.setName(motanParamExtInfo.getRpcProtocol());
+        }
         reference.setProtocol(protocolConfig);
         CommonClient obj = reference.getRef();
         if (Objects.nonNull(obj)) {
@@ -285,6 +288,8 @@ public final class ApplicationConfigCache {
 
         private Integer timeout;
 
+        private String rpcProtocol;
+
         /**
          * Gets method info.
          *
@@ -328,6 +333,18 @@ public final class ApplicationConfigCache {
         public void setTimeout(final Integer timeout) {
             this.timeout = timeout;
         }
+
+        public String getRpcProtocol() {
+            return rpcProtocol;
+        }
+
+        /**
+         * Sets rpc protocol.
+         * @param rpcProtocol the rpc protocol
+         */
+        public void setRpcProtocol(final String rpcProtocol) {
+            this.rpcProtocol = rpcProtocol;
+        }
     }
 
     /**
diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
index 405b876a5..ecc6f5c97 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
@@ -19,8 +19,10 @@ package org.apache.shenyu.plugin.motan.proxy;
 
 import com.weibo.api.motan.config.RefererConfig;
 import com.weibo.api.motan.proxy.CommonClient;
+import com.weibo.api.motan.rpc.Request;
 import com.weibo.api.motan.rpc.ResponseFuture;
 import com.weibo.api.motan.rpc.RpcContext;
+import com.weibo.api.motan.util.MotanClientUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.common.concurrent.ShenyuThreadFactory;
 import org.apache.shenyu.common.concurrent.ShenyuThreadPoolExecutor;
@@ -101,7 +103,10 @@ public class MotanProxyService {
         ResponseFuture responseFuture;
         //CHECKSTYLE:OFF IllegalCatch
         try {
-            responseFuture = (ResponseFuture) 
commonClient.asyncCall(metaData.getMethodName(), params, Object.class);
+            Request request = 
MotanClientUtil.buildRequest(reference.getServiceInterface(), 
metaData.getMethodName(), metaData.getParameterTypes(), params, null);
+            responseFuture = (ResponseFuture)commonClient.asyncCall(request, 
Object.class);
+            //responseFuture = (ResponseFuture) 
commonClient.asyncCall(metaData.getMethodName(), params, Object.class);
+
         } catch (Throwable e) {
             LOG.error("Exception caught in MotanProxyService#genericInvoker.", 
e);
             return null;
diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
index 3aea1514a..62bc0accd 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
@@ -107,16 +107,32 @@ public class ShenyuMotanClientConfiguration implements 
ApplicationListener<Conte
     /**
      * Define a bean with name of ProtocolConfigBean.
      *
-     * <p>The Default motan service name is "motan2"
+     * <p>The protocol id、name are "motan2",service export like this 
"motan2:8001".
      *
-     * @param shenyuMotanConfig shenyu motan shenyuMotanConfig
+     * @param shenyuMotanConfig shenyu motan config
      * @return ProtocolConfigBean
      */
     @Bean("motan2")
     public ProtocolConfigBean protocolConfig(final ShenyuMotanConfig 
shenyuMotanConfig) {
         ProtocolConfigBean config = new ProtocolConfigBean();
         config.setDefault(shenyuMotanConfig.getProtocol().isDefault());
-        config.setName(shenyuMotanConfig.getProtocol().getName());
+        config.setName("motan2");
+        
config.setMaxContentLength(shenyuMotanConfig.getProtocol().getMaxContentLength());
+        return config;
+    }
+
+    /**
+     * Define a bean with name of ProtocolConfigBean.
+     *
+     * <p>The protocol id、name are "motan",service export like this 
"motan:8001".
+     * @param shenyuMotanConfig shenyu motan config
+     * @return ProtocolConfigBean
+     */
+    @Bean("motan")
+    public ProtocolConfigBean motanProtocolConfig(final ShenyuMotanConfig 
shenyuMotanConfig) {
+        ProtocolConfigBean config = new ProtocolConfigBean();
+        config.setDefault(shenyuMotanConfig.getProtocol().isDefault());
+        config.setName("motan");
         
config.setMaxContentLength(shenyuMotanConfig.getProtocol().getMaxContentLength());
         return config;
     }
diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/property/ShenyuMotanConfig.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/property/ShenyuMotanConfig.java
index b2b8f4d7c..d4c7464ec 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/property/ShenyuMotanConfig.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/property/ShenyuMotanConfig.java
@@ -17,6 +17,8 @@
 
 package org.apache.shenyu.springboot.starter.client.motan.property;
 
+import org.apache.commons.lang3.StringUtils;
+
 /**
  * Shenyu motan properties.
  */
@@ -62,7 +64,7 @@ public class ShenyuMotanConfig {
 
         private boolean isDefault = true;
 
-        private String name = "motan2";
+        private String name;
 
         private Integer maxContentLength = 1048576;
 
@@ -87,7 +89,11 @@ public class ShenyuMotanConfig {
          * @return name
          */
         public String getName() {
-            return name;
+            if (StringUtils.isNotEmpty(name)) {
+                return name;
+            } else {
+                return "motan2";
+            }
         }
 
         /**

Reply via email to