From 5c97bddcda59008149defa6ed796d13ec5937ec1 Mon Sep 17 00:00:00 2001 From: chickenlj Date: Sat, 11 May 2024 20:28:08 +0800 Subject: [PATCH] add preferred protocol support --- .../apache/dubbo/common/constants/CommonConstants.java | 2 +- .../java/org/apache/dubbo/config/ProtocolConfig.java | 10 ++++++++++ .../dubbo/config/context/AbstractConfigManager.java | 2 +- .../src/main/resources/META-INF/compat/dubbo.xsd | 5 +++++ .../src/main/resources/META-INF/dubbo.xsd | 5 +++++ .../dubbo/registry/integration/RegistryDirectory.java | 4 ++-- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index 33f6281c19b..fc1f10025cf 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -601,7 +601,7 @@ public interface CommonConstants { String EXT_PROTOCOL = "ext.protocol"; - String PRIORITIZED_PROTOCOL = "prioritized.protocol"; + String PREFERRED_PROTOCOL = "preferred.protocol"; String IS_EXTRA = "isExtra"; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java index 1d0b5918a06..a838c35d126 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java @@ -231,6 +231,8 @@ public class ProtocolConfig extends AbstractConfig { */ private String extProtocol; + private String preferredProtocol; + /** * JSON check level for serialization. */ @@ -621,6 +623,14 @@ public void setExtProtocol(String extProtocol) { this.extProtocol = extProtocol; } + public String getPreferredProtocol() { + return preferredProtocol; + } + + public void setPreferredProtocol(String preferredProtocol) { + this.preferredProtocol = preferredProtocol; + } + public void mergeProtocol(ProtocolConfig sourceConfig) { if (sourceConfig == null) { return; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java index 5a15b14ac2f..b14495609fa 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java @@ -558,7 +558,7 @@ public List loadConfigsOfTypeFromProps(Class cl config.refresh(); } catch (Exception e) { throw new IllegalStateException( - "create default config instance failed, type:" + cls.getSimpleName()); + "create default config instance failed, type:" + cls.getSimpleName(), e); } this.addConfig(config); diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd index 91898219f58..745fcdc3a40 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd @@ -1305,6 +1305,11 @@ + + + + + diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd index 32f67add22b..73efe1fc59e 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd @@ -1716,6 +1716,11 @@ + + + + + diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index c6503753c59..9bdb9828eb7 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -67,7 +67,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; import static org.apache.dubbo.common.constants.CommonConstants.EXT_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_REGISTER_MODE; -import static org.apache.dubbo.common.constants.CommonConstants.PRIORITIZED_PROTOCOL; +import static org.apache.dubbo.common.constants.CommonConstants.PREFERRED_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_INIT_SERIALIZATION_OPTIMIZER; @@ -516,7 +516,7 @@ private Map> toInvokers(Map> oldUrlInvokerMap, L */ private String getEffectiveProtocol(String queryProtocols, URL url) { String protocol = url.getProtocol(); - String prioritizedProtocol = url.getParameter(PRIORITIZED_PROTOCOL, protocol); + String prioritizedProtocol = url.getParameter(PREFERRED_PROTOCOL, protocol); String effectiveProtocol = prioritizedProtocol;