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/01 00:23:05 UTC

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

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


##########
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java:
##########
@@ -175,10 +177,75 @@ 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/>
+        Collection<ConsumerConfig> consumers = applicationModel.getDefaultModule().getConfigManager().getConsumers();

Review Comment:
   read all modules (except internal  module)



##########
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java:
##########
@@ -175,10 +177,75 @@ 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/>
+        Collection<ConsumerConfig> consumers = applicationModel.getDefaultModule().getConfigManager().getConsumers();
+        if (CollectionUtils.isNotEmpty(consumers)) {
+            for (ConsumerConfig config : consumers) {
+                protocol = config.getProtocol();
+                if (StringUtils.isNotEmpty(protocol)) {
+                    break;
+                }
+            }
+        }
+        // <dubbo:provider/>
+        if (StringUtils.isEmpty(protocol)) {
+            Collection<ProviderConfig> providers = applicationModel.getDefaultModule().getConfigManager().getProviders();
+            if (CollectionUtils.isNotEmpty(providers)) {
+                for (ProviderConfig config : providers) {
+                    ProtocolConfig protocolConfig = config.getProtocol();
+                    protocol = protocolConfig != null ? protocolConfig.getName() : "";
+                    if (StringUtils.isNotEmpty(protocol)) {
+                        break;
+                    } else {
+                        List<ProtocolConfig> protocols = config.getProtocols();
+                        if (CollectionUtils.isNotEmpty(protocols)) {
+                            for (ProtocolConfig protocolCfg : protocols) {
+                                protocol = protocolCfg.getName();
+                                if (StringUtils.isNotEmpty(protocol)) {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        // <dubbo:protocol/>
+        if (StringUtils.isEmpty(protocol)) {
+            Collection<ProtocolConfig> protocols = applicationModel.getDefaultModule().getConfigManager().getProtocols();

Review Comment:
   ```suggestion
               Collection<ProtocolConfig> protocols = applicationModel.getApplicationConfigManager().getProtocols();
   ```



-- 
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