moremind commented on code in PR #5953:
URL: https://github.com/apache/shenyu/pull/5953#discussion_r2044862889


##########
shenyu-admin/src/main/resources/application.yml:
##########
@@ -21,7 +21,7 @@ spring:
   application:
     name: shenyu-admin
   profiles:
-    active: h2
+    active: mysql

Review Comment:
   not change this configuration



##########
shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java:
##########
@@ -26,6 +26,11 @@ public interface Constants {
      * The constant string separator.
      */
     String SEPARATOR_CHARS = ";";
+
+    /**
+     * The constant string separator.
+     */
+    String SEPARATOR_UNDERLINE = "_";

Review Comment:
   this is existed



##########
shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service/src/main/resources/application.yml:
##########
@@ -23,8 +23,9 @@ spring:
     allow-bean-definition-overriding: true
 dubbo:
   registry:
-    address: zookeeper://localhost:2181
-    
+    address: nacos://127.0.0.1:8849?namespace=namespace1
+#    address: zookeeper://localhost:2181

Review Comment:
   why change this?



##########
shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service/src/main/resources/application.yml:
##########
@@ -23,8 +23,9 @@ spring:
     allow-bean-definition-overriding: true
 dubbo:
   registry:
-    address: zookeeper://localhost:2181
-    
+    address: nacos://127.0.0.1:8849?namespace=namespace1
+#    address: zookeeper://localhost:2181
+
 shenyu:

Review Comment:
   not add this



##########
shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java:
##########
@@ -274,6 +376,120 @@ private ReferenceConfig<GenericService> 
buildReference(final MetaData metaData,
         return reference;
     }
 
+    /**
+     * buildReference param with dubboUpstream.
+     *
+     * @param metaData      metaData
+     * @param ruleData      ruleData
+     * @param namespace     namespace
+     * @param dubboUpstream dubboUpstream
+     * @return the reference config
+     */
+    private ReferenceConfig<GenericService> buildReference(final MetaData 
metaData, final RuleData ruleData, final String namespace, final DubboUpstream 
dubboUpstream) {
+        if (Objects.isNull(dubboUpstream)) {
+            return this.buildReference(metaData, namespace);
+        }
+
+        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
+        reference.setGeneric("true");
+        reference.setAsync(true);
+        reference.setApplication(applicationConfig);
+
+        RegistryConfig registryConfigTemp = new RegistryConfig();
+        registryConfigTemp.setProtocol(dubboUpstream.getProtocol());
+        registryConfigTemp.setId(Constants.DUBBO_DEFAULT_APPLICATION_NAME);
+        registryConfigTemp.setRegister(false);
+        registryConfigTemp.setAddress(dubboUpstream.getRegistry());
+        
Optional.ofNullable(dubboUpstream.getGroup()).ifPresent(registryConfigTemp::setGroup);
+        
Optional.ofNullable(dubboUpstream.getVersion()).ifPresent(registryConfigTemp::setVersion);
+        if (StringUtils.isNotBlank(namespace)) {
+            if 
(!registryConfigTemp.getAddress().contains(Constants.NAMESPACE)) {
+                registryConfigTemp.setAddress(registryConfigTemp.getAddress() 
+ "?" + Constants.NAMESPACE + "=" + namespace);

Review Comment:
   use common method!



##########
shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java:
##########
@@ -103,4 +108,80 @@ private CompletableFuture<Object> invokeAsync(final 
GenericService genericServic
         Object resultFromFuture = RpcContext.getContext().getFuture();
         return resultFromFuture instanceof CompletableFuture ? 
(CompletableFuture<Object>) resultFromFuture : 
CompletableFuture.completedFuture(resultFromFuture);
     }
+
+    /**
+     * get dubbo reference config.
+     *
+     * @param selectorData  the selector data
+     * @param ruleData      the rule data
+     * @param metaData      the meta data
+     * @param exchange      the webExchange
+     * @return dubbo reference config
+     */
+    private ReferenceConfig<GenericService> getReferenceConfig(final 
SelectorData selectorData, final RuleData ruleData, final MetaData metaData, 
final ServerWebExchange exchange) {
+        String referenceKey = metaData.getPath();
+        String namespace = "";
+        if 
(CollectionUtils.isNotEmpty(exchange.getRequest().getHeaders().get(Constants.NAMESPACE)))
 {
+            namespace = 
exchange.getRequest().getHeaders().get(Constants.NAMESPACE).get(0);
+        }
+
+        List<DubboUpstream> dubboUpstreams = 
GsonUtils.getInstance().fromList(selectorData.getHandle(), DubboUpstream.class);
+        dubboUpstreams = CollectionUtils.isEmpty(dubboUpstreams) ? null
+                : dubboUpstreams.stream().filter(u -> u.isStatus() && 
StringUtils.isNotBlank(u.getRegistry())).collect(Collectors.toList());
+        // if dubboUpstreams is empty, use default plugin config
+        if (CollectionUtils.isEmpty(dubboUpstreams)) {
+            referenceKey = StringUtils.isNotBlank(namespace) ? namespace + ":" 
+ referenceKey : referenceKey;

Review Comment:
   add common variable



##########
shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java:
##########
@@ -274,6 +376,120 @@ private ReferenceConfig<GenericService> 
buildReference(final MetaData metaData,
         return reference;
     }
 
+    /**
+     * buildReference param with dubboUpstream.
+     *
+     * @param metaData      metaData
+     * @param ruleData      ruleData
+     * @param namespace     namespace
+     * @param dubboUpstream dubboUpstream
+     * @return the reference config
+     */
+    private ReferenceConfig<GenericService> buildReference(final MetaData 
metaData, final RuleData ruleData, final String namespace, final DubboUpstream 
dubboUpstream) {
+        if (Objects.isNull(dubboUpstream)) {
+            return this.buildReference(metaData, namespace);
+        }
+
+        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
+        reference.setGeneric("true");

Review Comment:
   why "true"? not true?



##########
shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java:
##########
@@ -103,4 +108,80 @@ private CompletableFuture<Object> invokeAsync(final 
GenericService genericServic
         Object resultFromFuture = RpcContext.getContext().getFuture();
         return resultFromFuture instanceof CompletableFuture ? 
(CompletableFuture<Object>) resultFromFuture : 
CompletableFuture.completedFuture(resultFromFuture);
     }
+
+    /**
+     * get dubbo reference config.
+     *
+     * @param selectorData  the selector data
+     * @param ruleData      the rule data
+     * @param metaData      the meta data
+     * @param exchange      the webExchange
+     * @return dubbo reference config
+     */
+    private ReferenceConfig<GenericService> getReferenceConfig(final 
SelectorData selectorData, final RuleData ruleData, final MetaData metaData, 
final ServerWebExchange exchange) {
+        String referenceKey = metaData.getPath();
+        String namespace = "";
+        if 
(CollectionUtils.isNotEmpty(exchange.getRequest().getHeaders().get(Constants.NAMESPACE)))
 {
+            namespace = 
exchange.getRequest().getHeaders().get(Constants.NAMESPACE).get(0);
+        }
+
+        List<DubboUpstream> dubboUpstreams = 
GsonUtils.getInstance().fromList(selectorData.getHandle(), DubboUpstream.class);
+        dubboUpstreams = CollectionUtils.isEmpty(dubboUpstreams) ? null
+                : dubboUpstreams.stream().filter(u -> u.isStatus() && 
StringUtils.isNotBlank(u.getRegistry())).collect(Collectors.toList());
+        // if dubboUpstreams is empty, use default plugin config
+        if (CollectionUtils.isEmpty(dubboUpstreams)) {
+            referenceKey = StringUtils.isNotBlank(namespace) ? namespace + ":" 
+ referenceKey : referenceKey;
+            ReferenceConfig<GenericService> reference = 
ApacheDubboConfigCache.getInstance().get(referenceKey);
+            if (StringUtils.isEmpty(reference.getInterface())) {
+                ApacheDubboConfigCache.getInstance().invalidate(referenceKey);
+                reference = 
ApacheDubboConfigCache.getInstance().initRefN(metaData, namespace);
+            }
+            return reference;
+        }
+
+        List<Upstream> upstreams = this.convertUpstreamList(dubboUpstreams);
+        String ip = 
Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress();
+        Upstream upstream = LoadBalancerFactory.selector(upstreams, 
LoadBalanceEnum.RANDOM.getName(), ip);
+        DubboUpstream dubboUpstream = null;

Review Comment:
   judge null



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to