Skip to content

Commit 790dfce

Browse files
authored
Unregister onconnect and ondisconnect information (#7482)
* onconnect and ondisconnect should not be transmitted to Consumer side * fix import
1 parent 6cb16f9 commit 790dfce

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,13 @@ public interface CommonConstants {
381381
String ENABLE_NATIVE_JAVA_GENERIC_SERIALIZE = "dubbo.security.serialize.generic.native-java-enable";
382382

383383
String SERIALIZE_BLOCKED_LIST_FILE_PATH = "security/serialize.blockedlist";
384+
385+
386+
/**
387+
* Interface configuration item
388+
* @since 2.7.10
389+
*/
390+
String ON_CONNECT_KEY = "onconnect";
391+
392+
String ON_DISCONNECT_KEY = "ondisconnect";
384393
}

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
7878
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
7979
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
80+
import static org.apache.dubbo.common.constants.CommonConstants.ON_CONNECT_KEY;
81+
import static org.apache.dubbo.common.constants.CommonConstants.ON_DISCONNECT_KEY;
8082
import static org.apache.dubbo.common.constants.FilterConstants.VALIDATION_KEY;
8183
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
8284
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
@@ -370,29 +372,41 @@ protected URL getRegistryUrl(URL url) {
370372
* @return url to registry.
371373
*/
372374
private URL getUrlToRegistry(final URL providerUrl, final URL registryUrl) {
375+
376+
URL registeredProviderUrl = removeUselessParameters(providerUrl);
377+
373378
//The address you see at the registry
374379
if (!registryUrl.getParameter(SIMPLIFIED_KEY, false)) {
375-
return providerUrl.removeParameters(getHiddenKeys(providerUrl)).removeParameters(
380+
return registeredProviderUrl.removeParameters(getHiddenKeys(registeredProviderUrl)).removeParameters(
376381
MONITOR_KEY, BIND_IP_KEY, BIND_PORT_KEY, QOS_ENABLE, QOS_HOST, QOS_PORT, ACCEPT_FOREIGN_IP, VALIDATION_KEY,
377382
INTERFACES);
378383
} else {
379384
String extraKeys = registryUrl.getParameter(EXTRA_KEYS_KEY, "");
380385
// if path is not the same as interface name then we should keep INTERFACE_KEY,
381386
// otherwise, the registry structure of zookeeper would be '/dubbo/path/providers',
382387
// but what we expect is '/dubbo/interface/providers'
383-
if (!providerUrl.getPath().equals(providerUrl.getParameter(INTERFACE_KEY))) {
388+
if (!registeredProviderUrl.getPath().equals(registeredProviderUrl.getParameter(INTERFACE_KEY))) {
384389
if (StringUtils.isNotEmpty(extraKeys)) {
385390
extraKeys += ",";
386391
}
387392
extraKeys += INTERFACE_KEY;
388393
}
389394
String[] paramsToRegistry = getParamsToRegistry(DEFAULT_REGISTER_PROVIDER_KEYS
390395
, COMMA_SPLIT_PATTERN.split(extraKeys));
391-
return URL.valueOf(providerUrl, paramsToRegistry, providerUrl.getParameter(METHODS_KEY, (String[]) null));
396+
return URL.valueOf(registeredProviderUrl, paramsToRegistry, registeredProviderUrl.getParameter(METHODS_KEY, (String[]) null));
392397
}
393398

394399
}
395400

401+
/**
402+
* Remove information that does not require registration
403+
* @param providerUrl
404+
* @return
405+
*/
406+
private URL removeUselessParameters(URL providerUrl) {
407+
return providerUrl.removeParameters(ON_CONNECT_KEY, ON_DISCONNECT_KEY);
408+
}
409+
396410
private URL getSubscribedOverrideUrl(URL registeredProviderUrl) {
397411
return registeredProviderUrl.setProtocol(PROVIDER_PROTOCOL)
398412
.addParameters(CATEGORY_KEY, CONFIGURATORS_CATEGORY, CHECK_KEY, String.valueOf(false));

0 commit comments

Comments
 (0)