AlbumenJ commented on code in PR #10846:
URL: https://github.com/apache/dubbo/pull/10846#discussion_r1011029606


##########
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java:
##########
@@ -175,10 +178,82 @@ private String getSpecifiedProtocol() {
         if (StringUtils.isEmpty(protocol)) {
             Map<String, String> params = 
getApplicationConfig().getParameters();
             if (CollectionUtils.isNotEmptyMap(params)) {
-                protocol = 
getApplicationConfig().getParameters().get(METADATA_SERVICE_PROTOCOL_KEY);
+                protocol = params.get(METADATA_SERVICE_PROTOCOL_KEY);
             }
         }
 
+        return StringUtils.isNotEmpty(protocol) ? protocol : 
getRelatedOrDefaultProtocol();
+    }
+
+    /**
+     * Get other configured protocol from environment in priority order. If 
get nothing, use default dubbo.
+     *
+     * @return
+     */
+    private String getRelatedOrDefaultProtocol() {
+        String protocol = "";
+        // <dubbo:consumer/>
+        List<ModuleModel> moduleModels = applicationModel.getPubModuleModels();
+        breakPoint:

Review Comment:
   Do not use `breakPoint` and `break breakPoint` in Dubbo, pls. 
   It would be better to replaced with lambda.



##########
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java:
##########
@@ -175,10 +178,82 @@ private String getSpecifiedProtocol() {
         if (StringUtils.isEmpty(protocol)) {
             Map<String, String> params = 
getApplicationConfig().getParameters();
             if (CollectionUtils.isNotEmptyMap(params)) {
-                protocol = 
getApplicationConfig().getParameters().get(METADATA_SERVICE_PROTOCOL_KEY);
+                protocol = params.get(METADATA_SERVICE_PROTOCOL_KEY);
             }
         }
 
+        return StringUtils.isNotEmpty(protocol) ? protocol : 
getRelatedOrDefaultProtocol();
+    }
+
+    /**
+     * Get other configured protocol from environment in priority order. If 
get nothing, use default dubbo.
+     *
+     * @return
+     */
+    private String getRelatedOrDefaultProtocol() {
+        String protocol = "";
+        // <dubbo:consumer/>
+        List<ModuleModel> moduleModels = applicationModel.getPubModuleModels();
+        breakPoint:
+        for (ModuleModel moduleModel : moduleModels) {
+            Collection<ConsumerConfig> consumers = 
moduleModel.getConfigManager().getConsumers();
+            if (CollectionUtils.isNotEmpty(consumers)) {
+                for (ConsumerConfig config : consumers) {
+                    protocol = config.getProtocol();
+                    if (StringUtils.isNotEmpty(protocol)) {
+                        break breakPoint;
+                    }
+                }
+            }
+        }

Review Comment:
   ```suggestion
           protocol = moduleModels.stream()
                   .map(ModuleModel::getConfigManager)
                   .map(ModuleConfigManager::getConsumers)
                   .filter(CollectionUtils::isNotEmpty)
                   .flatMap(Collection::stream)
                   .map(ConsumerConfig::getProtocol)
                   .filter(StringUtils::isNotEmpty)
                   .findFirst()
                   .orElse(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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to