update version to 2.2.5.RC2

pull/1955/head
theonefx 4 years ago
commit 717eaa6111

@ -161,29 +161,16 @@ class UserConfig {
@Component
class SampleRunner implements ApplicationRunner {
@Value("${user.name:zz}")
String userName;
@Value("${user.age:25}")
int userAge;
@Autowired
private NacosConfigManager nacosConfigManager;
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println(
String.format("Initial username=%s, userAge=%d", userName, userAge));
nacosConfigManager.getConfigService().addListener(
"nacos-config-example.properties", "DEFAULT_GROUP", new Listener() {
"nacos-config-custom.properties", "DEFAULT_GROUP", new Listener() {
/**
* Callback with latest config data.
*
* For example, config data in Nacos is:
*
* user.name=Nacos user.age=25
* @param configInfo latest config data for specific dataId in Nacos
* server
*/

@ -5,21 +5,27 @@ spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos
## nacos-namespace cannot user 'public',cause by 'public' has special handing inside.
#spring.cloud.nacos.config.namespace=public
spring.cloud.nacos.config.name=test-aaa
spring.cloud.nacos.config.file-extension=yaml
## you can specify a custom name if you don't want to use the application name.
#spring.cloud.nacos.config.name=test-aaa
#spring.cloud.nacos.config.file-extension=yaml
## not recommended.
#spring.cloud.nacos.config.refreshable-dataids=common.properties
## not recommended.
#spring.cloud.nacos.config.shared-data-ids=common.properties,base-common.properties
#spring.cloud.nacos.config.shared-configs[0]= common333.properties
#spring.cloud.nacos.config.shared-configs[1].data-id= common111.properties
#spring.cloud.nacos.config.shared-configs[1].group= GROUP_APP1
#spring.cloud.nacos.config.shared-configs[1].refresh= true
#spring.cloud.nacos.config.shared-configs[2]= common222.properties
## recommended.
spring.cloud.nacos.config.shared-configs[0].data-id= test2.yaml
spring.cloud.nacos.config.shared-configs[0].refresh=true
## the default value is 'DEFAULT_GROUP' , if not specified.
spring.cloud.nacos.config.shared-configs[0].group= GROUP_APP1
## not recommended.
#spring.cloud.nacos.config.ext-config[0]=ext.properties
## recommended.
spring.cloud.nacos.config.extension-configs[0].data-id= extension1.properties
spring.cloud.nacos.config.extension-configs[0].refresh=true
spring.cloud.nacos.config.extension-configs[1].data-id= test1.yml

@ -74,10 +74,13 @@ public class RocketMQConsumerApplication {
while (true) {
mySink.input5().poll(m -> {
String payload = (String) m.getPayload();
if(payload.contains("0")){
throw new IllegalArgumentException("111111111111111111111111111111111111111111");
}
System.out.println("pull msg: " + payload);
}, new ParameterizedTypeReference<String>() {
});
Thread.sleep(2_000);
Thread.sleep(5_00);
}
}

@ -30,8 +30,6 @@ import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
import static com.alibaba.cloud.nacos.parser.AbstractNacosDataParser.DOT;
/**
* Nacos-specific loader, If need to support other methods of parsing,you need to do the
* following steps:
@ -47,6 +45,11 @@ import static com.alibaba.cloud.nacos.parser.AbstractNacosDataParser.DOT;
*/
public abstract class AbstractPropertySourceLoader implements PropertySourceLoader {
/**
* symbol: dot.
*/
static final String DOT = ".";
/**
* Prevent interference with other loaders.Nacos-specific loader, unless the reload
* changes it.

@ -25,7 +25,10 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import com.alibaba.cloud.nacos.utils.NacosConfigUtils;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.boot.env.PropertiesPropertySourceLoader;
import org.springframework.boot.env.PropertySourceLoader;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.PropertySource;
@ -33,25 +36,17 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import static com.alibaba.cloud.nacos.parser.AbstractPropertySourceLoader.DOT;
/**
* @author zkz
*/
public final class NacosDataParserHandler {
/**
* symbol: dot.
*/
public static final String DOT = ".";
/**
* constant.
*/
public static final String VALUE = "value";
/**
* default extension.
*/
public static final String DEFAULT_EXTENSION = "properties";
private static final String DEFAULT_EXTENSION = "properties";
private static List<PropertySourceLoader> propertySourceLoaders;
@ -80,8 +75,18 @@ public final class NacosDataParserHandler {
if (!canLoadFileExtension(propertySourceLoader, extension)) {
continue;
}
NacosByteArrayResource nacosByteArrayResource = new NacosByteArrayResource(
NacosByteArrayResource nacosByteArrayResource;
if (propertySourceLoader instanceof PropertiesPropertySourceLoader) {
// PropertiesPropertySourceLoader internal is to use the ISO_8859_1,
// the Chinese will be garbled, needs to transform into unicode.
nacosByteArrayResource = new NacosByteArrayResource(
NacosConfigUtils.selectiveConvertUnicode(configValue).getBytes(),
configName);
}
else {
nacosByteArrayResource = new NacosByteArrayResource(
configValue.getBytes(), configName);
}
nacosByteArrayResource.setFilename(getFileName(configName, extension));
List<PropertySource<?>> propertySourceList = propertySourceLoader
.load(configName, nacosByteArrayResource);

@ -28,14 +28,16 @@ import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import static com.alibaba.cloud.nacos.parser.AbstractNacosDataParser.DOT;
import static com.alibaba.cloud.nacos.parser.AbstractNacosDataParser.VALUE;
/**
* @author zkz
*/
public class NacosJsonPropertySourceLoader extends AbstractPropertySourceLoader {
/**
* constant.
*/
private static final String VALUE = "value";
/**
* Returns the file extensions that the loader supports (excluding the '.').
* @return the file extensions

@ -0,0 +1,61 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed 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
*
* https://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 com.alibaba.cloud.nacos.utils;
/**
* @author zkzlx
*/
public final class NacosConfigUtils {
private NacosConfigUtils(){
}
/**
* Convert Chinese characters to Unicode.
* @param configValue value of config
* @return new string
*/
public static String selectiveConvertUnicode(String configValue) {
StringBuilder sb = new StringBuilder();
char[] chars = configValue.toCharArray();
for (char aChar : chars) {
if (isChinese(aChar)) {
sb.append("\\u").append(Integer.toHexString(aChar));
}
else {
sb.append(aChar);
}
}
return sb.toString();
}
/**
* char is chinese?
* @param c a character
* @return true or false
*/
public static boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS;
}
}
Loading…
Cancel
Save