This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/cloud-native by this push:
new f8288cb Dubbo cloud native (#4943)
f8288cb is described below
commit f8288cb46c4d74a1de7493cae5791c087c168fda
Author: Mercy Ma <[email protected]>
AuthorDate: Mon Aug 26 17:16:25 2019 +0800
Dubbo cloud native (#4943)
* Polish apache/dubbo#4542 : [Enhancement] Adapt the Java standard
Event/Listener mechanism
* Polish apache/dubbo#4541 : [Feature] Add local File System
DynamicConfigurationFactory‘s extension
* Polish apache#4541 : Bugfix
* Polish apache/dubbo#4541 : Optimization
* Polish apache/dubbo#4541 : Add the compatibility for PollingWatchService
on the some platforms
* Polish apache/dubbo#4541 : Add delay publish without ThreadPoolExecutor
* Polish apache/dubbo#4541 : Refactor the extension name
* Polish apache/dubbo#4541 : Add remove ops
* Polish apache/dubbo#4541 : Add testable constructor
* Polish apache/dubbo#4541 : Add getConfigGroups method
* Polish apache/dubbo#4610 : [Refactor] Refactor the bootstrap module
* Polish apache/dubbo#4541 : Fix the nulling URL issue
* Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager
* Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager
* Polish apache/dubbo#4622 : Support multiple configcenters
* Polish apache/dubbo#4671 : ServiceNameMapping will not map the group,
version and protocol
* update referenceCount log (#4683)
Add comments to support multiple shared connections
* Polish /apache/dubbo#4687 : Remove the duplicated test code in
dubbo-config-spring (#4688)
* #4685 修改代码if判断false问题 if (hasException == false)修改成if (!hasException)
(#4695)
* Fixed Service annotation method parameters are not in effect (#4598)
* keep demo simple, and switch to use zookeeper as registry center (#4705)
* keep demo simple, and switch to use zookeeper as registry center
* remove comment
* @Reference auto-wires the instance of generic interface #4594 (#4677)
* try to shorten maven output to make travis build pass (#4710)
* use CountDownLatch to check zk registry if establish connection (#4589)
* Minor change
* Rename the extension name of WritableMetadataService
* Polish apache/dubbo#4759 : [Refactor] Change the signature of methods of
MetadataService #4759
* Merge remote-tracking branch 'upstream/master' into dubbo-cloud-native
# Conflicts:
# dubbo-all/pom.xml
# dubbo-bom/pom.xml
#
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java
#
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java
#
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java
#
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
#
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java
#
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
#
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java
#
dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java
#
dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java
#
dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java
#
dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
#
dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
#
dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
#
dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java
#
dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java
#
dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java
#
dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
#
dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java
#
dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java
#
dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilderTest.java
# dubbo-metadata/pom.xml
#
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java
#
dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
#
dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java
#
dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java
* Polish apache/dubbo#3984 : Add the implementation of
Page<ServiceInstance> getInstances(String serviceName, int offset, int
pageSize, boolean healthyOnly)
* Code merge
* Fix the cases
* Merge remote-tracking branch 'upstream/cloud-native' into
dubbo-cloud-native
# Conflicts:
#
dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
# dubbo-metadata/dubbo-metadata-definition-protobuf/pom.xml
#
dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java
#
dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryFactory.java
#
dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java
* Refactor ConfigManager
* Refactor ConfigManager
* Resolve the issues on ConfigManager
* Refactor and add test-cases for ConfigManager
* Polish apache/dubbo#4774 : [Feature] Dubbo Cloud Native - To Support in
Spring
* Polish apache/dubbo#4808 : [Feature] Add the registered/unregistered
event mechanism ShutdownHook
* Polish apache/dubbo#4807 : [Feature] Add the callback mechanism
ShutdownHook #4807
* Polish apache/dubbo#4813 : [Feature] add Prioritized implementation for
ServiceInstanceCustomizer
* Polish apache/dubbo#4815 : [Feature] Add the ServiceLoader for Dubbo's
services or components
* Polish apache/dubbo#4815 : [Feature] Add the ServiceLoader for Dubbo's
services or components
* Polish apache/dubbo#4813 : [Feature] add Prioritized implementation for
ServiceInstanceCustomizer
* Polish apache/dubbo#4807 : Add sort implementation
* Refactor
* Refactor
* Polish apache/dubbo#4845 : [Feature] Enhance the Event-Publishing feature
to original ServiceDiscovery
* Merge remote-tracking branch 'upstream/cloud-native' into
dubbo-cloud-native
# Conflicts:
#
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java
#
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
* Merge remote-tracking branch 'upstream/cloud-native' into
dubbo-cloud-native
# Conflicts:
#
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java
#
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
* Polish apache/dubbo#4854 : [Feature] MetadataService supports the Dubbo
protocol under auto-increased port
* Polish apache/dubbo#4857 : [Enhancement] Sync the Metadata storage type
into ApplicationConfig
* Polish apache/dubbo#4868 : [Enhancement] Refactor ConfigChangeEvent
* Polish apache/dubbo#4868 : [Enhancement] Refactor ConfigChangeEvent
* Polish apache/dubbo#4873 : [Feature] Add a conditional EventListener into
Event Module
* Polish apache/dubbo#4875 : [Feature] Refactor
ServiceInstancesChangedListener
* Remove the cycle dependencies
* Remove the cycle dependencies
* Polish apache/dubbo#4903 : [Feature] Set source into the BeanDefinition
of Dubbo Config
* Polish apache/dubbo#4902 : [Feature] Dubbo Cloud Native to Spring XML
scenario
* Polish apache/dubbo#4713 : Initial the new module and dependencies
* Polish apache/dubbo#4690 :
AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated
bean definitions
* Polish apache/dubbo#4690 :
AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated
bean definitions
* Polish apache/dubbo#4690 :
AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated
bean definitions
* Polish apache/dubbo#4910 : [Feature] To suppoort
DubboLifecycleComponentApplicationListener in Spring XML scenario
* Polish apache/dubbo#4713 : Add Service discovery implementation for
Eureka #4713
* Polish apache/dubbo#4713 : Add Service registration and discovery
implementation for Eureka
* Polish apache/dubbo#4713 : Add Service registration and discovery
implementation for Eureka
* Polish apache/dubbo#4920 : [Refactor] Extract the common implementation
for URLs' revision
* Refactor
* Polish apache/dubbo#4925 : ServiceDiscovery limits only one
ServiceInstancesChangedListener each service
* Polish apache/dubbo#4925 : ServiceDiscovery limits only one
ServiceInstancesChangedListener each service
* Remove useless classes
* Bugfix & Refactor ServiceDiscoveryRegistry
* Polish apache/dubbo#4937 : The calculation of Revision should add the
parameters of URL
* Polish apache/dubbo#4940 : NacosDynamicConfiguration supports
getConfigKeys method
* Polish apache/dubbo#4942 : Dubbo Cloud Native supports multiple protcols
---
.../NacosDubboServiceConsumerBootstrap.java | 4 +-
.../NacosDubboServiceProviderBootstrap.java | 4 +-
...=> ZookeeperDubboServiceConsumerBootstrap.java} | 20 +++--
.../ZookeeperDubboServiceProviderBootstrap.java | 38 +++++++++
.../support/nacos/NacosDynamicConfiguration.java | 71 ++++++++++++++++-
.../nacos/NacosDynamicConfigurationTest.java | 13 ++++
.../registry/client/ServiceDiscoveryRegistry.java | 52 ++++++-------
.../metadata/ProtocolPortsMetadataCustomizer.java | 51 +++++++++++++
.../metadata/ServiceInstanceMetadataUtils.java | 89 +++++++++++-----------
.../StandardMetadataServiceURLBuilder.java | 14 ++--
...dubbo.registry.client.ServiceInstanceCustomizer | 1 +
dubbo-registry/dubbo-registry-eureka/pom.xml | 13 ++++
12 files changed, 269 insertions(+), 101 deletions(-)
diff --git
a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceConsumerBootstrap.java
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceConsumerBootstrap.java
index 1bddcd3..aeb8eb7 100644
---
a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceConsumerBootstrap.java
+++
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceConsumerBootstrap.java
@@ -32,11 +32,11 @@ public class NacosDubboServiceConsumerBootstrap {
public static void main(String[] args) throws Exception {
ApplicationConfig applicationConfig = new
ApplicationConfig("dubbo-nacos-consumer-demo");
- applicationConfig.setMetadataType("remote");
+// applicationConfig.setMetadataType("remote");
new DubboBootstrap()
.application(applicationConfig)
// Zookeeper
- .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry.type=service&subscribed.services=dubbo-nacos-provider-demo"))
+ .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=dubbo-nacos-provider-demo"))
.metadataReport(new
MetadataReportConfig("nacos://127.0.0.1:8848"))
// Nacos
// .registry("consul", builder ->
builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo").group("namespace1"))
diff --git
a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceProviderBootstrap.java
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceProviderBootstrap.java
index bd47a7e..bf49d69 100644
---
a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceProviderBootstrap.java
+++
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceProviderBootstrap.java
@@ -30,11 +30,11 @@ public class NacosDubboServiceProviderBootstrap {
public static void main(String[] args) {
ApplicationConfig applicationConfig = new
ApplicationConfig("dubbo-nacos-provider-demo");
- applicationConfig.setMetadataType("remote");
+// applicationConfig.setMetadataType("remote");
new DubboBootstrap()
.application(applicationConfig)
// Zookeeper in service registry type
- .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry.type=service"))
+ .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry-type=service"))
// Nacos
// .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry.type=service"))
//
.registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry.type=service").build())
diff --git
a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceConsumerBootstrap.java
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java
similarity index 68%
copy from
dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceConsumerBootstrap.java
copy to
dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java
index 1bddcd3..8b45c1f 100644
---
a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/NacosDubboServiceConsumerBootstrap.java
+++
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java
@@ -17,8 +17,6 @@
package org.apache.dubbo.bootstrap;
import org.apache.dubbo.bootstrap.rest.UserService;
-import org.apache.dubbo.config.ApplicationConfig;
-import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.context.ConfigManager;
@@ -27,19 +25,13 @@ import org.apache.dubbo.config.context.ConfigManager;
*
* @since 2.7.4
*/
-public class NacosDubboServiceConsumerBootstrap {
+public class ZookeeperDubboServiceConsumerBootstrap {
public static void main(String[] args) throws Exception {
- ApplicationConfig applicationConfig = new
ApplicationConfig("dubbo-nacos-consumer-demo");
- applicationConfig.setMetadataType("remote");
new DubboBootstrap()
- .application(applicationConfig)
- // Zookeeper
- .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry.type=service&subscribed.services=dubbo-nacos-provider-demo"))
- .metadataReport(new
MetadataReportConfig("nacos://127.0.0.1:8848"))
- // Nacos
-// .registry("consul", builder ->
builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo").group("namespace1"))
+ .application("zookeeper-dubbo-consumer")
+ .registry("zookeeper", builder ->
builder.address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=zookeeper-dubbo-provider"))
.reference("echo", builder ->
builder.interfaceClass(EchoService.class).protocol("dubbo"))
.reference("user", builder ->
builder.interfaceClass(UserService.class).protocol("rest"))
.start()
@@ -51,10 +43,16 @@ public class NacosDubboServiceConsumerBootstrap {
EchoService echoService = referenceConfig.get();
+ ReferenceConfig<UserService> referenceConfig2 =
configManager.getReference("user");
+
+ UserService userService = referenceConfig2.get();
+
for (int i = 0; i < 500; i++) {
Thread.sleep(2000L);
System.out.println(echoService.echo("Hello,World"));
+ System.out.println(userService.getUser(i * 1L));
}
+
}
}
diff --git
a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/ZookeeperDubboServiceProviderBootstrap.java
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/ZookeeperDubboServiceProviderBootstrap.java
new file mode 100644
index 0000000..87d548d
--- /dev/null
+++
b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/ZookeeperDubboServiceProviderBootstrap.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.bootstrap;
+
+import org.apache.dubbo.bootstrap.rest.UserService;
+import org.apache.dubbo.bootstrap.rest.UserServiceImpl;
+
+/**
+ * TODO
+ */
+public class ZookeeperDubboServiceProviderBootstrap {
+
+ public static void main(String[] args) {
+ new DubboBootstrap()
+ .application("zookeeper-dubbo-provider")
+ .registry(builder ->
builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
+ .protocol("dubbo", builder -> builder.port(-1).name("dubbo"))
+ .protocol("rest", builder -> builder.port(8082).name("rest"))
+ .service("echo", builder ->
builder.interfaceClass(EchoService.class).ref(new
EchoServiceImpl()).protocolIds("dubbo"))
+ .service("user", builder ->
builder.interfaceClass(UserService.class).ref(new
UserServiceImpl()).protocolIds("rest"))
+ .start()
+ .await();
+ }
+}
diff --git
a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
index b82c8e7..3988d0b 100644
---
a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
+++
b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
@@ -26,26 +26,40 @@ import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.AbstractSharedListener;
import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.client.config.http.HttpAgent;
+import com.alibaba.nacos.client.config.impl.HttpSimpleClient;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.Executor;
+import java.util.stream.Stream;
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
+import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import static
com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
import static
org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPERATOR;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
@@ -54,17 +68,22 @@ import static
org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
*/
public class NacosDynamicConfiguration implements DynamicConfiguration {
+ private static final String GET_CONFIG_KEYS_PATH = "/v1/cs/configs";
+
private final Logger logger = LoggerFactory.getLogger(getClass());
/**
* the default timeout in millis to get config from nacos
*/
private static final long DEFAULT_TIMEOUT = 5000L;
+ private Properties nacosProperties;
+
/**
* The nacos configService
*/
+ private final ConfigService configService;
- private ConfigService configService;
+ private HttpAgent httpAgent;
/**
* The map store the key to {@link NacosConfigListener} mapping
@@ -72,12 +91,14 @@ public class NacosDynamicConfiguration implements
DynamicConfiguration {
private final ConcurrentMap<String, NacosConfigListener> watchListenerMap;
NacosDynamicConfiguration(URL url) {
- buildConfigService(url);
+ this.nacosProperties = buildNacosProperties(url);
+ this.configService = buildConfigService(url);
+ this.httpAgent = getHttpAgent(configService);
watchListenerMap = new ConcurrentHashMap<>();
}
private ConfigService buildConfigService(URL url) {
- Properties nacosProperties = buildNacosProperties(url);
+ ConfigService configService = null;
try {
configService = NacosFactory.createConfigService(nacosProperties);
} catch (NacosException e) {
@@ -89,6 +110,18 @@ public class NacosDynamicConfiguration implements
DynamicConfiguration {
return configService;
}
+ private HttpAgent getHttpAgent(ConfigService configService) {
+ HttpAgent agent = null;
+ try {
+ Field field = configService.getClass().getDeclaredField("agent");
+ field.setAccessible(true);
+ agent = (HttpAgent) field.get(configService);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ return agent;
+ }
+
public void publishNacosConfig(String key, String value) {
String[] keyAndGroup = getKeyAndGroup(key);
publishConfig(keyAndGroup[0], keyAndGroup[1], value);
@@ -143,6 +176,7 @@ public class NacosDynamicConfiguration implements
DynamicConfiguration {
putPropertyIfAbsent(url, properties, ACCESS_KEY);
putPropertyIfAbsent(url, properties, SECRET_KEY);
putPropertyIfAbsent(url, properties, CLUSTER_NAME);
+ putPropertyIfAbsent(url, properties, ENCODE);
}
private void putPropertyIfAbsent(URL url, Properties properties, String
propertyName) {
@@ -208,6 +242,36 @@ public class NacosDynamicConfiguration implements
DynamicConfiguration {
return null;
}
+ @Override
+ public SortedSet<String> getConfigKeys(String group) {
+ // TODO use Nacos Client API to replace HTTP Open API
+ SortedSet<String> keys = new TreeSet<>();
+ try {
+ List<String> paramsValues = asList("search", "accurate", "dataId",
"", "group", group, "pageNo", "1", "pageSize",
String.valueOf(Integer.MAX_VALUE));
+ String encoding = getProperty(ENCODE, "UTF-8");
+ HttpSimpleClient.HttpResult result =
httpAgent.httpGet(GET_CONFIG_KEYS_PATH, emptyList(), paramsValues, encoding, 5
* 1000);
+ Stream<String> keysStream = toKeysStream(result.content);
+ keysStream.forEach(keys::add);
+ } catch (IOException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ return keys;
+ }
+
+ private Stream<String> toKeysStream(String content) {
+ JSONObject jsonObject = JSON.parseObject(content);
+ JSONArray pageItems = jsonObject.getJSONArray("pageItems");
+ return pageItems.stream()
+ .map(object -> (JSONObject) object)
+ .map(json -> json.getString("dataId"));
+ }
+
+ private String getProperty(String name, String defaultValue) {
+ return nacosProperties.getProperty(name, defaultValue);
+ }
+
public class NacosConfigListener extends AbstractSharedListener {
private Set<ConfigurationListener> listeners = new
CopyOnWriteArraySet<>();
@@ -259,5 +323,4 @@ public class NacosDynamicConfiguration implements
DynamicConfiguration {
return ConfigChangeType.MODIFIED;
}
}
-
}
diff --git
a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
index 350936c..ac2978d 100644
---
a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
+++
b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
+import java.util.SortedSet;
import java.util.concurrent.CountDownLatch;
@@ -99,6 +100,18 @@ public class NacosDynamicConfigurationTest {
}
+ @Test
+ public void testGetConfigKeys() {
+
+ put("key1", "a");
+ put("key2", "b");
+
+ SortedSet<String> keys =
config.getConfigKeys(DynamicConfiguration.DEFAULT_GROUP);
+
+ Assertions.assertFalse(keys.isEmpty());
+
+ }
+
private void put(String key, String value) {
put(key, DynamicConfiguration.DEFAULT_GROUP, value);
}
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index 98f3275..84b5a75 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@ -76,10 +76,8 @@ import static
org.apache.dubbo.common.utils.StringUtils.isBlank;
import static
org.apache.dubbo.metadata.WritableMetadataService.DEFAULT_EXTENSION;
import static
org.apache.dubbo.registry.client.ServiceDiscoveryFactory.getExtension;
import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getExportedServicesRevision;
-import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams;
import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataStorageType;
-import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost;
-import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderPort;
+import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProtocolPort;
/**
* {@link ServiceDiscoveryRegistry} is the service-oriented {@link Registry}
and dislike the traditional one that
@@ -419,33 +417,27 @@ public class ServiceDiscoveryRegistry extends
FailbackRegistry {
serviceInstances.forEach(serviceInstance -> {
- List<URL> templateURLs = getTemplateURLs(subscribedURL,
serviceInstance);
- // The parameters of URLs that the MetadataService exported
- Map<String, Map<String, Object>> serviceURLsParams =
getMetadataServiceURLsParams(serviceInstance);
-
- serviceURLsParams.forEach((protocol, parametersMap) -> {
- templateURLs.stream()
- .filter(templateURL -> isCompatibleProtocol(protocol,
templateURL))
- .map(templateURL ->
templateURL.removeParameter(TIMESTAMP_KEY))
- .map(templateURL ->
templateURL.removeParameter(PID_KEY))
- .map(templateURL -> {
-
- String host = getProviderHost(parametersMap);
- Integer port = getProviderPort(parametersMap);
-
- if (Objects.equals(templateURL.getHost(), host)
- && Objects.equals(templateURL.getPort(),
port)) { // use templateURL if equals
- return templateURL;
- }
-
- URLBuilder clonedURLBuilder = from(templateURL) //
remove the parameters from the template URL
- .setHost(host) // reset the host
- .setPort(port); // reset the port
-
- return clonedURLBuilder.build();
- })
- .forEach(clonedURLs::add);
- });
+ String host = serviceInstance.getHost();
+
+ getTemplateURLs(subscribedURL, serviceInstance)
+ .stream()
+ .map(templateURL ->
templateURL.removeParameter(TIMESTAMP_KEY))
+ .map(templateURL -> templateURL.removeParameter(PID_KEY))
+ .map(templateURL -> {
+ String protocol = templateURL.getProtocol();
+ int port = getProtocolPort(serviceInstance, protocol);
+ if (Objects.equals(templateURL.getHost(), host)
+ && Objects.equals(templateURL.getPort(),
port)) { // use templateURL if equals
+ return templateURL;
+ }
+
+ URLBuilder clonedURLBuilder = from(templateURL) //
remove the parameters from the template URL
+ .setHost(host) // reset the host
+ .setPort(port); // reset the port
+
+ return clonedURLBuilder.build();
+ })
+ .forEach(clonedURLs::add);
});
return clonedURLs;
}
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ProtocolPortsMetadataCustomizer.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ProtocolPortsMetadataCustomizer.java
new file mode 100644
index 0000000..f7f8821
--- /dev/null
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ProtocolPortsMetadataCustomizer.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.registry.client.metadata;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.metadata.WritableMetadataService;
+import org.apache.dubbo.registry.client.ServiceInstance;
+import org.apache.dubbo.registry.client.ServiceInstanceCustomizer;
+import org.apache.dubbo.rpc.Protocol;
+
+import static org.apache.dubbo.metadata.WritableMetadataService.getExtension;
+import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataStorageType;
+import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.setProtocolPort;
+
+/**
+ * A Class to customize the ports of {@link Protocol protocols} into
+ * {@link ServiceInstance#getMetadata() the metadata of service instance}
+ *
+ * @since 2.7.4
+ */
+public class ProtocolPortsMetadataCustomizer implements
ServiceInstanceCustomizer {
+
+ @Override
+ public void customize(ServiceInstance serviceInstance) {
+
+ String metadataStoredType = getMetadataStorageType(serviceInstance);
+
+ WritableMetadataService writableMetadataService =
getExtension(metadataStoredType);
+
+ writableMetadataService.getExportedURLs()
+ .stream()
+ .map(URL::valueOf)
+ .forEach(url -> {
+ setProtocolPort(serviceInstance, url.getProtocol(),
url.getPort());
+ });
+ }
+}
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
index e3f3e4d..730d117 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.client.ServiceInstance;
+import org.apache.dubbo.rpc.Protocol;
import com.alibaba.fastjson.JSON;
@@ -28,7 +29,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import static java.lang.String.valueOf;
import static java.util.Collections.emptyMap;
import static org.apache.dubbo.common.utils.StringUtils.isBlank;
import static
org.apache.dubbo.metadata.WritableMetadataService.DEFAULT_METADATA_STORAGE_TYPE;
@@ -50,6 +50,16 @@ public class ServiceInstanceMetadataUtils {
public static final String METADATA_SERVICE_PREFIX =
"dubbo.metadata-service.";
/**
+ * The prefix of {@link Protocol} : "dubbo.protocols."
+ */
+ public static final String DUBBO_PROTOCOLS_PREFIX = "dubbo.protocols.";
+
+ /**
+ * The suffix of port : ".port";
+ */
+ public static final String DUBBO_PORT_SUFFIX = ".port";
+
+ /**
* The property name of metadata JSON of {@link MetadataService}'s {@link
URL}
*/
public static String METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME =
METADATA_SERVICE_PREFIX + "url-params";
@@ -77,16 +87,6 @@ public class ServiceInstanceMetadataUtils {
public static String METADATA_STORAGE_TYPE_PROPERTY_NAME =
"dubbo.metadata.storage-type";
/**
- * The property name of {@link URL url's} parameter name of Dubbo Provider
host
- */
- public static final String PROVIDER_HOST_PROPERTY_NAME = "provider.host";
-
- /**
- * The {@link URL url's} parameter name of Dubbo Provider port
- */
- public static final String PROVIDER_PORT_PROPERTY_NAME = "provider.port";
-
- /**
* Get the multiple {@link URL urls'} parameters of {@link MetadataService
MetadataService's} Metadata
*
* @param serviceInstance the instance of {@link ServiceInstance}
@@ -110,23 +110,6 @@ public class ServiceInstanceMetadataUtils {
return params.getOrDefault(protocol, emptyMap());
}
- /**
- * The provider port from {@link ServiceInstance the specified service
instance}
- *
- * @param serviceInstance {@link ServiceInstance the specified service
instance}
- * @param protocol the protocol name
- * @return The protocol port if found, or <code>null</code>
- */
- public static Integer getProviderPort(ServiceInstance serviceInstance,
String protocol) {
- Map<String, Object> params =
getMetadataServiceURLParams(serviceInstance, protocol);
- return getProviderPort(params);
- }
-
- public static String getProviderHost(ServiceInstance serviceInstance,
String protocol) {
- Map<String, Object> params =
getMetadataServiceURLParams(serviceInstance, protocol);
- return getProviderHost(params);
- }
-
public static String getMetadataServiceParameter(List<URL> urls) {
Map<String, Map<String, String>> params = new HashMap<>();
@@ -145,21 +128,9 @@ public class ServiceInstanceMetadataUtils {
private static Map<String, String> getParams(URL providerURL) {
Map<String, String> params = new LinkedHashMap<>();
setDefaultParams(params, providerURL);
- // set provider host
- setProviderHostParam(params, providerURL);
- // set provider port
- setProviderPortParam(params, providerURL);
return params;
}
- public static String getProviderHost(Map<String, Object> params) {
- return valueOf(params.get(PROVIDER_HOST_PROPERTY_NAME));
- }
-
- public static Integer getProviderPort(Map<String, Object> params) {
- return
Integer.valueOf(valueOf(params.get(PROVIDER_PORT_PROPERTY_NAME)));
- }
-
/**
* The revision for all exported Dubbo services from the specified {@link
ServiceInstance}.
*
@@ -228,12 +199,42 @@ public class ServiceInstanceMetadataUtils {
|| metadata.containsKey(METADATA_SERVICE_URLS_PROPERTY_NAME);
}
- private static void setProviderHostParam(Map<String, String> params, URL
providerURL) {
- params.put(PROVIDER_HOST_PROPERTY_NAME, providerURL.getHost());
+ /**
+ * Create the property name of Dubbo protocol port
+ *
+ * @param protocol the name of protocol, e.g, dubbo, rest, and so on
+ * @return e.g, "dubbo.protocols.dubbo.port"
+ */
+ public static String createProtocolPortPropertyName(String protocol) {
+ return DUBBO_PROTOCOLS_PREFIX + protocol + DUBBO_PORT_SUFFIX;
}
- private static void setProviderPortParam(Map<String, String> params, URL
providerURL) {
- params.put(PROVIDER_PORT_PROPERTY_NAME,
valueOf(providerURL.getPort()));
+ /**
+ * Set the protocol port into {@link ServiceInstance#getMetadata() the
metadata of service instance}
+ *
+ * @param serviceInstance {@link ServiceInstance service instance}
+ * @param protocol the name of protocol, e.g, dubbo, rest, and so on
+ * @param port the port of protocol
+ */
+ public static void setProtocolPort(ServiceInstance serviceInstance, String
protocol, int port) {
+ Map<String, String> metadata = serviceInstance.getMetadata();
+ String propertyName = createProtocolPortPropertyName(protocol);
+ metadata.put(propertyName, Integer.toString(port));
+ }
+
+ /**
+ * Get the property value of port by the specified {@link
ServiceInstance#getMetadata() the metadata of
+ * service instance} and protocol
+ *
+ * @param serviceInstance {@link ServiceInstance service instance}
+ * @param protocol the name of protocol, e.g, dubbo, rest, and so on
+ * @return if not found, return <code>null</code>
+ */
+ public static Integer getProtocolPort(ServiceInstance serviceInstance,
String protocol) {
+ Map<String, String> metadata = serviceInstance.getMetadata();
+ String propertyName = createProtocolPortPropertyName(protocol);
+ String propertyValue = metadata.get(propertyName);
+ return propertyValue == null ? null : Integer.valueOf(propertyValue);
}
/**
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java
index 48022af..d420ff9 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java
@@ -27,8 +27,7 @@ import java.util.Map;
import static java.lang.String.valueOf;
import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams;
-import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost;
-import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderPort;
+import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProtocolPort;
/**
* The {@link MetadataServiceURLBuilder} implementation for The standard Dubbo
scenario
@@ -51,14 +50,13 @@ public class StandardMetadataServiceURLBuilder implements
MetadataServiceURLBuil
List<URL> urls = new ArrayList<>(paramsMap.size());
- for (Map.Entry<String, Map<String, Object>> entry :
paramsMap.entrySet()) {
+ String host = serviceInstance.getHost();
- URLBuilder urlBuilder = new URLBuilder();
+ for (Map.Entry<String, Map<String, Object>> entry :
paramsMap.entrySet()) {
String protocol = entry.getKey();
- Map<String, Object> urlParams = entry.getValue();
- String host = getProviderHost(urlParams);
- Integer port = getProviderPort(urlParams);
- urlBuilder.setHost(host)
+ Integer port = getProtocolPort(serviceInstance, protocol);
+ URLBuilder urlBuilder = new URLBuilder()
+ .setHost(host)
.setPort(port)
.setProtocol(protocol)
.setPath(MetadataService.class.getName());
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.ServiceInstanceCustomizer
b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.ServiceInstanceCustomizer
index 7b06893..a83cb72 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.ServiceInstanceCustomizer
+++
b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.ServiceInstanceCustomizer
@@ -2,3 +2,4 @@
org.apache.dubbo.registry.client.metadata.MetadataServiceURLParamsMetadataCustom
org.apache.dubbo.registry.client.metadata.ExportedServicesRevisionMetadataCustomizer
org.apache.dubbo.registry.client.metadata.SubscribedServicesRevisionMetadataCustomizer
org.apache.dubbo.registry.client.metadata.RefreshServiceMetadataCustomizer
+org.apache.dubbo.registry.client.metadata.ProtocolPortsMetadataCustomizer
diff --git a/dubbo-registry/dubbo-registry-eureka/pom.xml
b/dubbo-registry/dubbo-registry-eureka/pom.xml
index cd4181d..79bbc22 100644
--- a/dubbo-registry/dubbo-registry-eureka/pom.xml
+++ b/dubbo-registry/dubbo-registry-eureka/pom.xml
@@ -27,7 +27,20 @@
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
+
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>2.1</version>
+ </dependency>
+
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>