You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2022/01/08 15:37:16 UTC
[dubbo] branch 3.0 updated: fix client parameters, consumer parameters was not included (#9545)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 65bd70b fix client parameters, consumer parameters was not included (#9545)
65bd70b is described below
commit 65bd70b54c87539ccc843b938479f0b7c2ea8d20
Author: ken.lj <ke...@gmail.com>
AuthorDate: Sat Jan 8 23:36:43 2022 +0800
fix client parameters, consumer parameters was not included (#9545)
---
.../src/main/java/org/apache/dubbo/common/URL.java | 4 ++++
.../common/url/component/DubboServiceAddressURL.java | 19 +++++++++++++++++++
.../dubbo/common/url/component/ServiceAddressURL.java | 16 ----------------
.../dubbo/rpc/protocol/dubbo/DubboProtocol.java | 9 +++++----
4 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 5fe417a..08b0f1d 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -508,6 +508,10 @@ class URL implements Serializable {
return urlParam.getParameters();
}
+ public Map<String, String> getAllParameters() {
+ return this.getParameters();
+ }
+
/**
* Get the parameters to be selected(filtered)
*
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/DubboServiceAddressURL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/DubboServiceAddressURL.java
index b929988..1de2dfe 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/DubboServiceAddressURL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/DubboServiceAddressURL.java
@@ -21,6 +21,8 @@ import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ServiceModel;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -90,6 +92,23 @@ public class DubboServiceAddressURL extends ServiceAddressURL {
return value;
}
+ /**
+ * The returned parameters is imprecise regarding override priorities of consumer url and provider url.
+ * This method is only used to pass the configuration in the 'client'.
+ */
+ @Override
+ public Map<String, String> getAllParameters() {
+ Map<String, String> allParameters = new HashMap<>((int)(super.getParameters().size()/.75 + 1));
+ allParameters.putAll(super.getParameters());
+ if (consumerURL != null) {
+ allParameters.putAll(consumerURL.getParameters());
+ }
+ if (overrideURL != null) {
+ allParameters.putAll(overrideURL.getParameters());
+ }
+ return Collections.unmodifiableMap(allParameters);
+ }
+
public ServiceConfigURL getOverrideURL() {
return overrideURL;
}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceAddressURL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceAddressURL.java
index 8c36d90..862d2d3 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceAddressURL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceAddressURL.java
@@ -100,22 +100,6 @@ public abstract class ServiceAddressURL extends URL {
return consumerURL.getVersion();
}
- /**
- * FIXME, Avoid calling this method on the main line.
- */
-// @Override
-// public Map<String, String> getParameters() {
-// Map<String, String> allParameters = new HashMap<>((int)(super.getParameters().size()/.75 + 1));
-// allParameters.putAll(super.getParameters());
-// if (consumerURL != null) {
-// allParameters.putAll(consumerURL.getParameters());
-// }
-// if (overriddenURL != null) {
-// allParameters.putAll(overriddenURL.getParameters());
-// }
-// allParameters.remove(CATEGORY_KEY);
-// return Collections.unmodifiableMap(allParameters);
-// }
@Override
public String getParameter(String key) {
// call corresponding methods directly, then we can remove the following if branches.
diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
index a4f201e..5d9040c 100644
--- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
+++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
@@ -627,9 +627,6 @@ public class DubboProtocol extends AbstractProtocol {
* which means params are shared among different services. Since client is shared among services this is currently not a problem.
*/
String str = url.getParameter(CLIENT_KEY, url.getParameter(SERVER_KEY, DEFAULT_REMOTING_CLIENT));
- url = url.addParameter(CODEC_KEY, DubboCodec.NAME);
- // enable heartbeat by default
- url = url.addParameterIfAbsent(HEARTBEAT_KEY, String.valueOf(DEFAULT_HEARTBEAT));
// BIO is not allowed since it has severe performance issue.
if (StringUtils.isNotEmpty(str) && !url.getOrDefaultFrameworkModel().getExtensionLoader(Transporter.class).hasExtension(str)) {
@@ -640,7 +637,11 @@ public class DubboProtocol extends AbstractProtocol {
ExchangeClient client;
try {
// Replace InstanceAddressURL with ServiceConfigURL.
- url = new ServiceConfigURL(DubboCodec.NAME, url.getUsername(), url.getPassword(), url.getHost(), url.getPort(), url.getPath(), url.getParameters());
+ url = new ServiceConfigURL(DubboCodec.NAME, url.getUsername(), url.getPassword(), url.getHost(), url.getPort(), url.getPath(), url.getAllParameters());
+ url = url.addParameter(CODEC_KEY, DubboCodec.NAME);
+ // enable heartbeat by default
+ url = url.addParameterIfAbsent(HEARTBEAT_KEY, String.valueOf(DEFAULT_HEARTBEAT));
+
// connection should be lazy
if (url.getParameter(LAZY_CONNECT_KEY, false)) {
client = new LazyConnectExchangeClient(url, requestHandler);