You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/11/05 03:33:41 UTC

[GitHub] [dubbo] pandaapo commented on a diff in pull request #10846: fix issue: get available protocol for metadata service.

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


##########
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:
    Thank you so much for your review! But it seems that the logic below can't be realized by lambda.
   https://github.com/apache/dubbo/blob/33c2d1250194104dae4f446783926ef2429478e1/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java#L215-L230, now it is `ProtocolConfig` first `List<ProtocolConfig>` second in one `ProviderConfig`.
   ```
   Stream<ProviderConfig> providerConfigStream = moduleModels.stream()
                   .map(ModuleModel::getConfigManager)
                   .map(ModuleConfigManager::getProviders)
                   .filter(CollectionUtils::isNotEmpty)
                   .flatMap(Collection::stream);
   protocol = providerConfigStream
       .map(ProviderConfig::getProtocol)
       .filter((protocolConfig) -> protocolConfig != null)
       .map(ProtocolConfig::getName)
       .findFirst()
       .orElse("");
   if (StringUtils.isEmpty(protocol)) {
       protocol = providerConfigStream
           .map(ProviderConfig::getProtocols)
           .filter(CollectionUtils::isNotEmpty)
           .flatMap(Collection::stream)
           .map(ProtocolConfig::getName)
           .filter(StringUtils::isNotEmpty)
           .findFirst()
           .orElse("");
   }
   ```
   
   After using lambda, it becomes `ProtocolConfig` in all `ProviderConfig` first, then `List<ProviderConfig>` in all `ProviderConfig`.
   Do you have a better way to refactor this logic in lambda? Thank you.



-- 
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-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org