Skip to content

Commit

Permalink
Merge pull request #116 from chuntaojun/feature_remote_first
Browse files Browse the repository at this point in the history
Feature remote first
  • Loading branch information
chuntaojun authored Mar 17, 2020
2 parents f4a6216 + 9e20b30 commit e9290b8
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nacos-config-spring-boot-actuator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>nacos-spring-boot-parent</artifactId>
<groupId>com.alibaba.boot</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion nacos-config-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class NacosConfigProperties {

private String password;

private boolean remoteFirst = false;

@JSONField(serialize = false)
private List<Config> extConfig = new ArrayList<>();

Expand Down Expand Up @@ -233,6 +235,14 @@ public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
}

public boolean isRemoteFirst() {
return remoteFirst;
}

public void setRemoteFirst(boolean remoteFirst) {
this.remoteFirst = remoteFirst;
}

public List<Config> getExtConfig() {
return extConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Properties;
import java.util.function.Function;

Expand All @@ -34,6 +35,7 @@

import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.util.StringUtils;

import static com.alibaba.nacos.spring.util.NacosUtils.buildDefaultPropertySourceName;
Expand Down Expand Up @@ -69,8 +71,15 @@ public void loadConfig() {
globalProperties, config.getType());
sources.addAll(elements);
}
for (NacosPropertySource propertySource : sources) {
mutablePropertySources.addLast(propertySource);
if (nacosConfigProperties.isRemoteFirst()) {
for (ListIterator<NacosPropertySource> itr = sources.listIterator(sources.size()); itr.hasPrevious();) {
mutablePropertySources.addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, itr.previous());
}
} else {
for (NacosPropertySource propertySource : sources) {
mutablePropertySources.addLast(propertySource);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion nacos-config-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion nacos-discovery-spring-boot-actuator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>nacos-spring-boot-parent</artifactId>
<groupId>com.alibaba.boot</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion nacos-discovery-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion nacos-discovery-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion nacos-spring-boot-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion nacos-spring-boot-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-project</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion nacos-spring-boot-samples/nacos-config-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-samples</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class PrintLogger {
@Autowired
private LoggingSystem loggingSystem;

@NacosConfigListener(dataId = "nacos.log", timeout = 5000)
@NacosConfigListener(dataId = "${nacos.example.listener.data-id}", timeout = 5000)
public void onChange(String newLog) throws Exception {
Properties properties = new DefaultPropertiesConfigParse().parse(newLog);
for (Object t : properties.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
nacos.example.listener.data-id=nacos.log

nacos.config.bootstrap.enable=true
nacos.config.server-addr=127.0.0.1:9100
nacos.config.remote-first=true

nacos.config.data-ids=people,test
nacos.config.group=DEVELOP
Expand Down
2 changes: 1 addition & 1 deletion nacos-spring-boot-samples/nacos-discovery-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-samples</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion nacos-spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</properties>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-project</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>

<packaging>pom</packaging>

Expand Down

0 comments on commit e9290b8

Please sign in to comment.