Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with metadata-type not work since 2.7.5 describe in issue #5667 #5694

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,17 @@ public interface CommonConstants {

String METADATA_REVISION = "metadata.revision";

/**
* since 2.7.5 in dubbo.xsd "metadata" has been modified to "metadata-type"
*/
@Deprecated
String METADATA_KEY = "metadata";

/**
* since 2.7.5 in dubbo.xsd "metadata" has been modified to "metadata-type"
*/
String METADATA_TYPE_KEY = "metadata.type";

String DEFAULT_METADATA_STORAGE_TYPE = "local";

String REMOTE_METADATA_STORAGE_TYPE = "remote";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ public void checkAndUpdateSubConfigs() {
}
// get consumer's global configuration
checkDefault();
// init some null configuration.
List<ConfigInitializer> configInitializers = ExtensionLoader.getExtensionLoader(ConfigInitializer.class)
.getActivateExtension(URL.valueOf("configInitializer://"), (String[]) null);
configInitializers.forEach(e -> e.initReferConfig(this));

this.refresh();
if (getGeneric() == null && getConsumer() != null) {
setGeneric(getConsumer().getGeneric());
Expand Down Expand Up @@ -494,4 +489,4 @@ private void postProcessConfig() {
Invoker<?> getInvoker() {
return invoker;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -711,4 +711,4 @@ public DubboBootstrap getBootstrap() {
public void setBootstrap(DubboBootstrap bootstrap) {
this.bootstrap = bootstrap;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public boolean publishConfig(String key, String group, String content) {
boolean published = false;
String resolvedGroup = resolveGroup(group);
try {
String value = configService.getConfig(key, resolvedGroup, -1L);
String value = configService.getConfig(key, resolvedGroup, DEFAULT_TIMEOUT);
if (StringUtils.isNotEmpty(value)) {
content = value + "," + content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import java.util.SortedSet;
import java.util.concurrent.CountDownLatch;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;


/**
* Unit test for nacos config center support
Expand Down Expand Up @@ -140,6 +143,16 @@ public static void setUp() {
}
}

@Test
public void testPublishConfig() {
String key = "user-service";
String group = "org.apache.dubbo.service.UserService";
String content = "test";

assertTrue(config.publishConfig(key, group, content));
assertEquals("test", config.getProperties(key, group));
}

@AfterAll
public static void tearDown() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metadata.store.InMemoryWritableMetadataService;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.Map;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.METADATA_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METADATA_TYPE_KEY;
import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;

/**
Expand Down Expand Up @@ -96,6 +101,29 @@ static WritableMetadataService getDefaultExtension() {
return getExtensionLoader(WritableMetadataService.class).getDefaultExtension();
}

/**
* Get
*
* @param paramMap
* @return
*/
static WritableMetadataService getExtensionForCompatible(Map<String, String> paramMap){
String metadataType = paramMap.get(METADATA_TYPE_KEY);
if(StringUtils.isEmpty(metadataType)){
/**
* Since 2.7.5 in dubbo.xsd "metadata" has been modified to "metadata-type".
* But a bug occurs which leads "metadata-type" not work, some developers maybe
* use self-defined such as flowing to make metadata reporter work:
* <dubbo:parameter key="metadata" value="remote"/>
* @see https://github.com/apache/dubbo/issues/5667
*
* The following code aims to be compatible with this case.
*/
metadataType = paramMap.get(METADATA_KEY);
}
return getExtension(StringUtils.isEmpty(metadataType) ? DEFAULT_METADATA_STORAGE_TYPE : metadataType);
}

static WritableMetadataService getExtension(String name) {
return getExtensionLoader(WritableMetadataService.class).getOrDefaultExtension(name);
}
Expand Down