From 5d32b86f2af54dbe71f5842f75f552f7465937dc Mon Sep 17 00:00:00 2001 From: cvictory Date: Thu, 6 Jun 2019 17:14:40 +0800 Subject: [PATCH] Merge changes from 2.7.2-release (#4259) --- CHANGES.md | 89 +++++++++++++++++ README.md | 2 +- .../alibaba/dubbo/rpc/support/RpcUtils.java | 5 - .../nacos/NacosDynamicConfiguration.java | 96 ++++++++++--------- .../nacos/NacosDynamicConfigurationTest.java | 47 ++++++--- dubbo-dependencies-bom/pom.xml | 8 +- .../dubbo-dependencies-zookeeper/pom.xml | 2 +- .../store/nacos/NacosMetadataReport.java | 12 ++- .../store/nacos/NacosMetadataReportTest.java | 8 +- .../dubbo/registry/nacos/NacosRegistry.java | 2 +- .../java/org/apache/dubbo/rpc/Constants.java | 4 - .../org/apache/dubbo/rpc/RpcInvocation.java | 2 +- .../dubbo/rpc/proxy/AbstractProxyInvoker.java | 6 +- .../apache/dubbo/rpc/support/RpcUtils.java | 18 ++-- .../dubbo/rpc/protocol/dubbo/DubboCodec.java | 5 +- .../rpc/protocol/dubbo/DubboInvoker.java | 9 +- pom.xml | 2 +- 17 files changed, 212 insertions(+), 105 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6296565891..22495c441d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,94 @@ # Release Notes +## 2.7.2 + +### New Features + +- nacos config center / metadata center support. [#3846](https://github.com/apache/dubbo/issues/3846) +- Etcd support as config center and metadata center [#3653](https://github.com/apache/dubbo/issues/3653) +- Support Redis cluster in Metadata Report. [#3817](https://github.com/apache/dubbo/issues/3817) +- add new module for Dubbo Event. [#4096](https://github.com/apache/dubbo/issues/4096) +- Support multiple registry that including some effective registry, such as zk, redis [#3599](https://github.com/apache/dubbo/issues/3599) +- support nacos metadata [#4025](https://github.com/apache/dubbo/issues/4025) +- Dubbo support Google Protobuf generic reference [#3829](https://github.com/apache/dubbo/issues/3829) +- Merge serialization-native-hessian-for-apache-dubbo into incubator-dubbo [#3961](https://github.com/apache/dubbo/issues/3961) +- Merge rpc-native-thrift-for-apache-dubbo into incubator-dubbo [#3960](https://github.com/apache/dubbo/issues/3960) +- add socks5 proxy support [#3624](https://github.com/apache/dubbo/issues/3624) +- Integrate with SOFARegistry [#3874](https://github.com/apache/dubbo/issues/3874) +- Introduce CompletableFuture $invokeAsync for GenericService, now, for generic call, you can use: + $invoke for sync method call with normal return type. + $invokeAsync for async method call with CompletableFuture signature. [#3163](https://github.com/apache/dubbo/issues/3163) + +### Enhancement + +- Performance tuning for TimeoutTask in DefaultFuture. [#4129](https://github.com/apache/dubbo/issues/4129) +- Add a script to check dependencies license. [#3840](https://github.com/apache/dubbo/issues/3840) +- Change DynamicConfiguration definition to better adapt to Apollo's namespace storage model.[#3266](https://github.com/apache/dubbo/issues/3266) +- use equal explicit class to replace anonymous class [#4027](https://github.com/apache/dubbo/issues/4027) +- Seperate Constants.java into some SubConstants Class [#3137](https://github.com/apache/dubbo/issues/3137) +- Need to enhance DecodeableRpcResult error message [#3994](https://github.com/apache/dubbo/issues/3994) +- Provide more meaningful binary releases. [#2491](https://github.com/apache/dubbo/issues/2491) +- remove useless module-dubbo-test-integration [#3573](https://github.com/apache/dubbo/issues/3573) +- complete lookup method of consul registry and add integration test [#3890](https://github.com/apache/dubbo/issues/3890) +- Metrics Service [#3702](https://github.com/apache/dubbo/issues/3702) +- Update nacos-client to 1.0.0 [#3804](https://github.com/apache/dubbo/issues/3804) +- Fluent style builder API support [#3431](https://github.com/apache/dubbo/issues/3431) +- Update readme to remove the incubator prefix [#4159](https://github.com/apache/dubbo/issues/4159) +- update erlang link [#4100](https://github.com/apache/dubbo/issues/4100) +- optimize array code style [#4031](https://github.com/apache/dubbo/issues/4031) +- optimize some code style [#4006](https://github.com/apache/dubbo/issues/4006) +- remove useless module-dubbo-test-integration [#3989](https://github.com/apache/dubbo/issues/3989) +- optimize constant naming style [#3970](https://github.com/apache/dubbo/issues/3970) +- Use maven CI friendly versions: revision. [#3851](https://github.com/apache/dubbo/issues/3851) +- remove-parse-error-log [#3862](https://github.com/apache/dubbo/issues/3862) +- Complete xsd definition for ConfigCenterConfig. [#3854](https://github.com/apache/dubbo/issues/3854) +- add remoteApplicationName field in RpcContext [#3816](https://github.com/apache/dubbo/issues/3816) + +### Bugfixes + +- @Reference can't match the local @Service beans. [#4071](https://github.com/apache/dubbo/issues/4071) +- remove some illegal licence: jcip-annotations, jsr173_api. [#3790](https://github.com/apache/dubbo/issues/3790) +- Qos port can't be disabled by externalized property. [#3958](https://github.com/apache/dubbo/issues/3958) +- Fix consumer will generate wrong stackTrace. [#4137](https://github.com/apache/dubbo/issues/4137) +- nacos registry serviceName may conflict. [#4111](https://github.com/apache/dubbo/issues/4111) +- The client loses the listener when the network is reconnected. [#4115](https://github.com/apache/dubbo/issues/4115) +- fix registery urls increase forever when recreate reference proxy. [#4109](https://github.com/apache/dubbo/issues/4109) +- In dubbo 2.7.1,the watcher processor of zookeeper client throw Nullpointexception. [#3866](https://github.com/apache/dubbo/issues/3866) +- ReferenceConfig initialized not changed to false once subscribe throws exception [#4068](https://github.com/apache/dubbo/issues/4068) +- dubbo registry extension compatibility with dubbo 2.6.x. [#3882](https://github.com/apache/dubbo/issues/3882) +- Annotation mode cannot set service parameters in 2.7.0. [#3778](https://github.com/apache/dubbo/issues/3778) +- compatibility with Zipkin. [#3728](https://github.com/apache/dubbo/issues/3728) +- do local export before register any listener. [#3669](https://github.com/apache/dubbo/issues/3669) +- Cannot recognize 2.6.x compatible rules from dubbo-admin. [#4059](https://github.com/apache/dubbo/issues/4059) +- In Dubbo 2.7.0, the provider can't be configured to async [#3650](https://github.com/apache/dubbo/issues/3650) +- dubbox compatibility [#3991](https://github.com/apache/dubbo/issues/3991) +- dubbo-2.7.1 providers repeat register [#3785](https://github.com/apache/dubbo/issues/3785) +- consul registry: NullPointerException [#3923](https://github.com/apache/dubbo/issues/3923) +- cannot publish local ip address when local ip and public ip exist at the same time [#3802](https://github.com/apache/dubbo/issues/3802) +- roll back change made by 3520. [#3935](https://github.com/apache/dubbo/issues/3935) +- dubbo-registry-nacos module is not bundled into Apache Dubbo 2.7.1 [#3797](https://github.com/apache/dubbo/issues/3797) +- switch from CopyOnWriteArrayList to regular list in order to avoid potential UnsupportedOperationException [#3242](https://github.com/apache/dubbo/issues/3242) +- Serialization ContentTypeId conflict between avro protocol and protocoluff protocol [#3926](https://github.com/apache/dubbo/issues/3926) +- delay export function doesn't work. [#3952](https://github.com/apache/dubbo/issues/3952) +- org.apache.dubbo.rpc.support.MockInvoker#getInterface should not return null [#3713](https://github.com/apache/dubbo/issues/3713) +- dubbo TagRouter does not work with dubbo:parameter [#3875](https://github.com/apache/dubbo/issues/3875) +- make protocols a mutable list (a concrete ArrayList) [#3841](https://github.com/apache/dubbo/issues/3841) +- javadoc lint issue [#3646](https://github.com/apache/dubbo/issues/3646) +- The etcd3 lease should be recycled correctly [#3684](https://github.com/apache/dubbo/issues/3684) +- telnet can't work when parameter has no nullary constructor and some fields is primitive [#4007](https://github.com/apache/dubbo/issues/4007) +- Sort added router list before set the 'routers' field of the RouterChain [#3969](https://github.com/apache/dubbo/issues/3969) +- fix injvm and local call [#3638](https://github.com/apache/dubbo/issues/3638) +- spelling error in org.apache.dubbo.common.extension.AdaptiveClassCodeGenerator#generateReturnAndInovation [#3933](https://github.com/apache/dubbo/issues/3933) +- metadata report doesn't support redis with password [#3826](https://github.com/apache/dubbo/issues/3826) +- The dubbo protostuff protocol serializes the bug of java.sql.Timestamp [#3914](https://github.com/apache/dubbo/issues/3914) +- do not filter thread pool by port [#3919](https://github.com/apache/dubbo/issues/3919) +- 'dubbo-serialization-gson' maven package error [#3903](https://github.com/apache/dubbo/issues/3903) +- AbstractRegistry will be endless loop, when doSaveProperties method have no permission to save the file [#3746](https://github.com/apache/dubbo/issues/3746) +- fix fastjson serialization with generic return type [#3771](https://github.com/apache/dubbo/issues/3771) +- The dubbo-serialization -api modules should not dependency on third-party jar packages [#3762](https://github.com/apache/dubbo/issues/3762) +- when using protostuff to serialize, there is not to check whether the data is null [#3727](https://github.com/apache/dubbo/issues/3727) +- bugfix and enhancement for async [#3287](https://github.com/apache/dubbo/issues/3287) + ## 2.7.1 ### Notice diff --git a/README.md b/README.md index 6c8ae12fde..d3c76302dc 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ There's a [README](https://github.com/apache/dubbo-samples/tree/master/dubbo-sam ```xml - 2.7.1 + 2.7.2 diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java index d7db04fe10..378f14adc2 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java @@ -21,7 +21,6 @@ import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import java.lang.reflect.Type; -import java.util.Map; /** * 2019-04-18 @@ -76,8 +75,4 @@ public class RpcUtils extends org.apache.dubbo.rpc.support.RpcUtils { public static boolean isOneway(URL url, Invocation inv) { return org.apache.dubbo.rpc.support.RpcUtils.isOneway(url.getOriginalURL(), inv); } - - public static Map getNecessaryAttachments(Invocation inv) { - return org.apache.dubbo.rpc.support.RpcUtils.getNecessaryAttachments(inv); - } } 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 96bec25f1d..fa04c0036b 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 @@ -46,9 +46,6 @@ 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 org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPERATOR; -import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR; -import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY; /** @@ -57,11 +54,10 @@ import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY; public class NacosDynamicConfiguration implements DynamicConfiguration { private final Logger logger = LoggerFactory.getLogger(getClass()); - /** - * The final root path would be: /$NAME_SPACE/config + * the default timeout in millis to get config from nacos */ - private String rootPath; + private static final long DEFAULT_TIMEOUT = 5000L; /** * The nacos configService @@ -75,7 +71,6 @@ public class NacosDynamicConfiguration implements DynamicConfiguration { private final ConcurrentMap watchListenerMap; NacosDynamicConfiguration(URL url) { - rootPath = url.getParameter(CONFIG_NAMESPACE_KEY, DEFAULT_GROUP) + "-config"; buildConfigService(url); watchListenerMap = new ConcurrentHashMap<>(); } @@ -93,24 +88,6 @@ public class NacosDynamicConfiguration implements DynamicConfiguration { return configService; } - public void publishNacosConfig(String key, String value) { - try { - String[] keyAndGroup = getKeyAndGroup(key); - configService.publishConfig(keyAndGroup[0], keyAndGroup[1], value); - } catch (NacosException e) { - logger.error(e.getErrMsg()); - } - } - - private String[] getKeyAndGroup(String key) { - int i = key.lastIndexOf(GROUP_CHAR_SEPERATOR); - if (i < 0) { - return new String[]{key, null}; - } else { - return new String[]{key.substring(0, i), key.substring(i+1)}; - } - } - private Properties buildNacosProperties(URL url) { Properties properties = new Properties(); setServerAddr(url, properties); @@ -162,43 +139,70 @@ public class NacosDynamicConfiguration implements DynamicConfiguration { return configListener; } + + /** + * FIXME: 2019-05-30 to remove this function + * Nacos server does not support * as valid character of data-id. + * If a Dubbo service specifies group. For example: + * + * + * + * The key passed to NacosDynamicConfiguration will be sth. like: + * test*org.apache.dubbo.demo.DemoService:1.0.0.test.configurators + * + * See logic in org.apache.dubbo.common.URL#getEncodedServiceKey() + * + * The purpose of this function is to convert the * into :, to keep align with + * the implementation in NacosRegistry. + * + * In the future this logic should be removed if Dubbo core can handle this. + * @param key + * @return + */ + private String normalizedKey(String key) { + return key.replaceFirst("\\*", ":"); + } + @Override public void addListener(String key, String group, ConfigurationListener listener) { - String[] keyAndGroup = getKeyAndGroup(key); - if (keyAndGroup[1] != null) { - group = keyAndGroup[1]; - } - String finalGroup = group; - NacosConfigListener nacosConfigListener = watchListenerMap.computeIfAbsent(generateKey(key, group), k -> createTargetListener(key, finalGroup)); - String keyInNacos = rootPath + PROPERTIES_CHAR_SEPERATOR + key; + String normalizedKey = normalizedKey(key); + NacosConfigListener nacosConfigListener = watchListenerMap.computeIfAbsent(normalizedKey, k -> createTargetListener(normalizedKey, group)); nacosConfigListener.addListener(listener); try { - configService.addListener(keyInNacos, group, nacosConfigListener); - System.out.println("1"); + configService.addListener(normalizedKey, group, nacosConfigListener); } catch (NacosException e) { logger.error(e.getMessage()); } } - private String generateKey(String key, String group) { - if (StringUtils.isNotEmpty(group)) { - key = key + GROUP_CHAR_SEPERATOR + group; - } - return key; - } - @Override public void removeListener(String key, String group, ConfigurationListener listener) { - NacosConfigListener eventListener = watchListenerMap.get(generateKey(key, group)); + String normalizedKey = normalizedKey(key); + NacosConfigListener eventListener = watchListenerMap.get(normalizedKey); if (eventListener != null) { eventListener.removeListener(listener); } } + /** + * FIXME the model of Zookeeper and Nacos is inconsistent, need to remove this function in next release. + */ + @Override + public String getConfig(String key) { + return getConfig(key, DEFAULT_GROUP, -1L); + } + @Override public String getConfig(String key, String group, long timeout) throws IllegalStateException { - key = generateKey(key, group); - return (String) getInternalProperty(rootPath + PROPERTIES_CHAR_SEPERATOR + key); + try { + String normalizedKey = normalizedKey(key); + long nacosTimeout = timeout < 0 ? DEFAULT_TIMEOUT : timeout; + return configService.getConfig(normalizedKey, group, nacosTimeout); + } catch (NacosException e) { + logger.error(e.getMessage()); + } + return null; } @Override @@ -209,8 +213,8 @@ public class NacosDynamicConfiguration implements DynamicConfiguration { @Override public Object getInternalProperty(String key) { try { - String[] keyAndGroup = getKeyAndGroup(key); - return configService.getConfig(keyAndGroup[0], keyAndGroup[1], 5000L); + String normalizedKey = normalizedKey(key); + return configService.getConfig(normalizedKey, DEFAULT_GROUP, DEFAULT_TIMEOUT); } catch (NacosException e) { logger.error(e.getMessage()); } 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 ff785b974a..28fa234b79 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 @@ -17,10 +17,14 @@ package org.apache.dubbo.configcenter.support.nacos; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; import org.apache.dubbo.common.URL; import org.apache.dubbo.configcenter.ConfigChangeEvent; import org.apache.dubbo.configcenter.ConfigurationListener; +import org.apache.dubbo.configcenter.DynamicConfiguration; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -42,15 +46,22 @@ public class NacosDynamicConfigurationTest { private static NacosDynamicConfiguration config; + /** + * A test client to put data to Nacos server for testing purpose + */ + private static ConfigService nacosClient; + @Test public void testGetConfig() throws Exception { - - put("dubbo-config-org.apache.dubbo.nacos.testService.configurators", "hello"); + put("org.apache.dubbo.nacos.testService.configurators", "hello"); Thread.sleep(200); - put("dubbo-config-dubbo.properties:test", "aaa=bbb"); + put("dubbo.properties", "test", "aaa=bbb"); + Thread.sleep(200); + put("xxxx:org.apache.dubbo.demo.DemoService:1.0.0.test.configurators", "helloworld"); Thread.sleep(200); Assertions.assertEquals("hello", config.getConfig("org.apache.dubbo.nacos.testService.configurators")); Assertions.assertEquals("aaa=bbb", config.getConfig("dubbo.properties", "test")); + Assertions.assertEquals("helloworld", config.getConfig("xxxx*org.apache.dubbo.demo.DemoService:1.0.0.test.configurators")); } @Test @@ -67,19 +78,19 @@ public class NacosDynamicConfigurationTest { config.addListener("testapp.tagrouters", listener3); config.addListener("testapp.tagrouters", listener4); - put("dubbo-config-AService.configurators", "new value1"); + put("AService.configurators", "new value1"); Thread.sleep(200); - put("dubbo-config-testapp.tagrouters", "new value2"); + put("testapp.tagrouters", "new value2"); Thread.sleep(200); - put("dubbo-config-testapp", "new value3"); + put("testapp", "new value3"); Thread.sleep(5000); latch.await(); - Assertions.assertEquals(1, listener1.getCount("dubbo-config-AService.configurators")); - Assertions.assertEquals(1, listener2.getCount("dubbo-config-AService.configurators")); - Assertions.assertEquals(1, listener3.getCount("dubbo-config-testapp.tagrouters")); - Assertions.assertEquals(1, listener4.getCount("dubbo-config-testapp.tagrouters")); + Assertions.assertEquals(1, listener1.getCount("AService.configurators")); + Assertions.assertEquals(1, listener2.getCount("AService.configurators")); + Assertions.assertEquals(1, listener3.getCount("testapp.tagrouters")); + Assertions.assertEquals(1, listener4.getCount("testapp.tagrouters")); Assertions.assertEquals("new value1", listener1.getValue()); Assertions.assertEquals("new value1", listener2.getValue()); @@ -89,8 +100,12 @@ public class NacosDynamicConfigurationTest { } private void put(String key, String value) { + put(key, DynamicConfiguration.DEFAULT_GROUP, value); + } + + private void put(String key, String group, String value) { try { - config.publishNacosConfig(key, value); + nacosClient.publishConfig(key, group, value); } catch (Exception e) { System.out.println("Error put value to nacos."); } @@ -103,10 +118,18 @@ public class NacosDynamicConfigurationTest { URL url = URL.valueOf(urlForDubbo) .addParameter(SESSION_TIMEOUT_KEY, 15000); config = new NacosDynamicConfiguration(url); + + + try { + nacosClient = NacosFactory.createConfigService("127.0.0.1:8848"); + } catch (NacosException e) { + e.printStackTrace(); + } } @AfterAll public static void tearDown() { + } private class TestListener implements ConfigurationListener { @@ -121,7 +144,7 @@ public class NacosDynamicConfigurationTest { @Override public void process(ConfigChangeEvent event) { System.out.println(this + ": " + event); - Integer count = countMap.computeIfAbsent(event.getKey(), k -> new Integer(0)); + Integer count = countMap.computeIfAbsent(event.getKey(), k -> 0); countMap.put(event.getKey(), ++count); value = event.getValue(); latch.countDown(); diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 3573df1ed3..20c17b6631 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -153,7 +153,7 @@ 6.1.26 2.0 1.1.0 - 2.7.2-SNAPSHOT + 2.7.3-SNAPSHOT @@ -597,6 +597,12 @@ io.etcd jetcd-launcher ${etcd_launcher_version} + + + com.github.spotbugs + spotbugs-annotations + + org.testcontainers diff --git a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml index 66dba910f4..968e5e35bc 100644 --- a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml +++ b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml @@ -32,7 +32,7 @@ pom - 2.7.2-SNAPSHOT + 2.7.3-SNAPSHOT 1.1.0 diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java index 03bdeb8f95..b12e4f014f 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java @@ -37,18 +37,28 @@ import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY; /** * metadata report impl for nacos */ public class NacosMetadataReport extends AbstractMetadataReport { + private static final Logger logger = LoggerFactory.getLogger(NacosMetadataReport.class); + private ConfigService configService; + /** + * The group used to store metadata in Nacos + */ + private String group; + + public NacosMetadataReport(URL url) { super(url); this.configService = buildConfigService(url); + group = url.getParameter(GROUP_KEY, DEFAULT_ROOT); } public ConfigService buildConfigService(URL url) { @@ -113,7 +123,7 @@ public class NacosMetadataReport extends AbstractMetadataReport { private void storeMetadata(MetadataIdentifier identifier, String value) { try { - boolean publishResult = configService.publishConfig(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), identifier.getGroup(), value); + boolean publishResult = configService.publishConfig(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), group, value); if (!publishResult) { throw new RuntimeException("publish nacos metadata failed"); } diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java index 07d6f8b839..a6cf8f5dc5 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java @@ -45,10 +45,12 @@ public class NacosMetadataReportTest { private NacosMetadataReportFactory nacosMetadataReportFactory; private ConfigService configService; + private static final String NACOS_GROUP = "zzz"; + @BeforeEach public void setUp() { // timeout in 15 seconds. - URL url = URL.valueOf("nacos://127.0.0.1:8848") + URL url = URL.valueOf("nacos://127.0.0.1:8848?group=" + NACOS_GROUP) .addParameter(SESSION_TIMEOUT_KEY, 15000); nacosMetadataReportFactory = new NacosMetadataReportFactory(); this.nacosMetadataReport = (NacosMetadataReport) nacosMetadataReportFactory.createMetadataReport(url); @@ -66,7 +68,7 @@ public class NacosMetadataReportTest { String application = "nacos-metdata-report-test"; MetadataIdentifier providerIdentifier = storeProvider(nacosMetadataReport, TEST_SERVICE, version, group, application); - String serverContent = configService.getConfig(providerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), group, 5000L); + String serverContent = configService.getConfig(providerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, 5000L); Assertions.assertNotNull(serverContent); Gson gson = new Gson(); @@ -81,7 +83,7 @@ public class NacosMetadataReportTest { String application = "nacos-metadata-report-consumer-test"; MetadataIdentifier consumerIdentifier = storeConsumer(nacosMetadataReport, TEST_SERVICE, version, group, application); - String serverContent = configService.getConfig(consumerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), group, 5000L); + String serverContent = configService.getConfig(consumerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, 5000L); Assertions.assertNotNull(serverContent); Assertions.assertEquals(serverContent, "{\"paramConsumerTest\":\"nacosConsumer\"}"); } diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java index 6639962fa8..5483052847 100644 --- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java +++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java @@ -383,7 +383,7 @@ public class NacosRegistry extends FailbackRegistry { */ private String[] getCategories(URL url) { return ANY_VALUE.equals(url.getServiceInterface()) ? - ALL_SUPPORTED_CATEGORIES : of(DEFAULT_CATEGORY); + ALL_SUPPORTED_CATEGORIES : url.getParameter(CATEGORY_KEY,new String[]{DEFAULT_CATEGORY}); } private URL buildURL(Instance instance) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java index 5085887e87..f5159601a8 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java @@ -84,10 +84,6 @@ public interface Constants { String ASYNC_KEY = "async"; - String FUTURE_GENERATED_KEY = "future_generated"; - - String FUTURE_RETURNTYPE_KEY = "future_returntype"; - String RETURN_KEY = "return"; String TOKEN_KEY = "token"; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java index 06b7cb6a0d..d972537371 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java @@ -93,7 +93,7 @@ public class RpcInvocation implements Invocation, Serializable { } public RpcInvocation(Method method, Object[] arguments) { - this(method.getName(), method.getParameterTypes(), arguments, null, null); + this(method, arguments, null); } public RpcInvocation(Method method, Object[] arguments, Map attachment) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java index fe42fb2c6b..4008c447ba 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java @@ -27,7 +27,6 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.support.RpcUtils; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.CompletableFuture; @@ -112,10 +111,7 @@ public abstract class AbstractProxyInvoker implements Invoker { private CompletableFuture wrapWithFuture (Object value, Invocation invocation) { if (RpcContext.getContext().isAsyncStarted()) { return ((AsyncContextImpl)(RpcContext.getContext().getAsyncContext())).getInternalFuture(); - } else if (RpcUtils.isReturnTypeFuture(invocation)) { - if (value == null) { - return CompletableFuture.completedFuture(null); - } + } else if (value instanceof CompletableFuture) { return (CompletableFuture) value; } return CompletableFuture.completedFuture(value); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java index 955cb31f98..2d70a9ed8e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java @@ -27,8 +27,6 @@ import org.apache.dubbo.rpc.RpcInvocation; import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicLong; @@ -36,7 +34,6 @@ import static org.apache.dubbo.rpc.Constants.$INVOKE; import static org.apache.dubbo.rpc.Constants.$INVOKE_ASYNC; import static org.apache.dubbo.rpc.Constants.ASYNC_KEY; import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; -import static org.apache.dubbo.rpc.Constants.FUTURE_GENERATED_KEY; import static org.apache.dubbo.rpc.Constants.ID_KEY; import static org.apache.dubbo.rpc.Constants.RETURN_KEY; /** @@ -171,7 +168,12 @@ public class RpcUtils { } public static boolean isReturnTypeFuture(Invocation inv) { - Class clazz = getReturnType(inv); + Class clazz; + if (inv instanceof RpcInvocation) { + clazz = ((RpcInvocation) inv).getReturnType(); + } else { + clazz = getReturnType(inv); + } return (clazz != null && CompletableFuture.class.isAssignableFrom(clazz)) || isGenericAsync(inv); } @@ -198,12 +200,4 @@ public class RpcUtils { } return isOneway; } - - public static Map getNecessaryAttachments(Invocation inv) { - Map attachments = new HashMap<>(inv.getAttachments()); - attachments.remove(ASYNC_KEY); - attachments.remove(FUTURE_GENERATED_KEY); - return attachments; - } - } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java index dd3e847748..3b8fe66901 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java @@ -33,17 +33,16 @@ import org.apache.dubbo.remoting.transport.CodecSupport; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcInvocation; -import org.apache.dubbo.rpc.support.RpcUtils; import java.io.IOException; import java.io.InputStream; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.encodeInvocationArgument; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DECODE_IN_IO_THREAD_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_DECODE_IN_IO_THREAD; -import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; /** * Dubbo codec. @@ -186,7 +185,7 @@ public class DubboCodec extends ExchangeCodec { out.writeObject(encodeInvocationArgument(channel, inv, i)); } } - out.writeObject(RpcUtils.getNecessaryAttachments(inv)); + out.writeObject(inv.getAttachments()); } @Override diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index f40b664e16..ece71497c5 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -23,7 +23,6 @@ import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.TimeoutException; import org.apache.dubbo.remoting.exchange.ExchangeClient; -import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.AsyncRpcResult; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; @@ -97,13 +96,7 @@ public class DubboInvoker extends AbstractInvoker { } else { AsyncRpcResult asyncRpcResult = new AsyncRpcResult(inv); CompletableFuture responseFuture = currentClient.request(inv, timeout); - responseFuture.whenComplete((obj, t) -> { - if (t != null) { - asyncRpcResult.completeExceptionally(t); - } else { - asyncRpcResult.complete((AppResponse) obj); - } - }); + asyncRpcResult.subscribeTo(responseFuture); RpcContext.getContext().setFuture(new FutureAdapter(asyncRpcResult)); return asyncRpcResult; } diff --git a/pom.xml b/pom.xml index 16afc2714f..338a613b45 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ true true - 2.7.2-SNAPSHOT + 2.7.3-SNAPSHOT