Skip to content

Commit

Permalink
修改nacos-client 2.2.1版本,适配 (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
985492783 authored May 10, 2023
1 parent 9591915 commit e8cae2c
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ classes
/bin/
*.prefs
*~
.extract
.extract
.flattened-pom.xml
31 changes: 28 additions & 3 deletions nacos-spring-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<artifactId>nacos-spring-parent</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.1.1</version>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-spring-context</artifactId>
<version>1.1.1</version>
<version>${revision}</version>
<name>Alibaba Nacos :: Spring :: Context</name>
<packaging>jar</packaging>

Expand All @@ -30,6 +30,22 @@
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos.version}</version>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.4</version>
</dependency>

<!--yaml-->
Expand All @@ -43,6 +59,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -72,6 +89,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.9</version>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -81,4 +106,4 @@

</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.lang.reflect.Method;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
Expand All @@ -54,7 +54,7 @@
public abstract class AnnotationListenerMethodProcessor<A extends Annotation>
implements ApplicationListener<ContextRefreshedEvent> {

protected final Log logger = LogFactory.getLog(getClass());
protected final Logger logger = LoggerFactory.getLogger(getClass());
private final Class<A> annotationType;

public AnnotationListenerMethodProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ public boolean publishConfig(String dataId, String group, String content, String
return published;
}

@Override
public boolean publishConfigCas(String dataId, String group, String content, String casMd5) throws NacosException {
boolean published = configService.publishConfigCas(dataId, group, content, casMd5);
publishEvent(new NacosConfigPublishedEvent(configService, dataId, group, content,
published));
return published;
}

@Override
public boolean publishConfigCas(String dataId, String group, String content, String casMd5, String type)
throws NacosException {
boolean published = configService.publishConfigCas(dataId, group, content, casMd5, type);
publishEvent(new NacosConfigPublishedEvent(configService, dataId, group, content,
published));
return published;
}

@Override
public boolean removeConfig(String dataId, String group) throws NacosException {
boolean removed = configService.removeConfig(dataId, group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected void bind(final Object bean, final String beanName,
environment);
final String type;

ConfigType typeEunm = properties.yaml() ? ConfigType.YAML : properties.type();
ConfigType typeEunm = properties.type();
if (ConfigType.UNSET.equals(typeEunm)) {
type = NacosUtils.readFileExtension(dataId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ public void registerInstance(String serviceName, String groupName, Instance inst
throws NacosException {
delegate.registerInstance(serviceName, groupName, instance);
}


@Override
public void batchRegisterInstance(String serviceName, String groupName, List<Instance> instances)
throws NacosException {
delegate.batchRegisterInstance(serviceName, groupName, instances);
}

@Override
public void batchDeregisterInstance(String serviceName, String groupName, List<Instance> instances)
throws NacosException {
delegate.batchDeregisterInstance(serviceName, groupName, instances);
}

@Override
public void deregisterInstance(String serviceName, String ip, int port)
throws NacosException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ protected Map<Object, Object> constructMapping(MappingNode node) {
}

@Override
protected Map<Object, Object> createDefaultMap() {
final Map<Object, Object> delegate = super.createDefaultMap();
protected Map<Object, Object> createDefaultMap(int initSize) {
final Map<Object, Object> delegate = super.createDefaultMap(initSize);
return new AbstractMap<Object, Object>() {
@Override
public Object put(Object key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,60 @@ public void run() {

return true;
}


@Override
public boolean publishConfigCas(String dataId, String group, final String content, String casMd5) throws NacosException {
String key = createKey(dataId, group);
contentCache.put(key, content);

List<Listener> listeners = listenersCache.get(key);
if (!CollectionUtils.isEmpty(listeners)) {
for (final Listener listener : listeners) {
Executor executor = listener.getExecutor();
if (executor != null) {
executor.execute(new Runnable() {
@Override
public void run() {
listener.receiveConfigInfo(content);
}
});
}
else {
listener.receiveConfigInfo(content);
}
}
}

return true;
}

@Override
public boolean publishConfigCas(String dataId, String group, final String content, String casMd5, String type)
throws NacosException {
String key = createKey(dataId, group, type);
contentCache.put(key, content);

List<Listener> listeners = listenersCache.get(key);
if (!CollectionUtils.isEmpty(listeners)) {
for (final Listener listener : listeners) {
Executor executor = listener.getExecutor();
if (executor != null) {
executor.execute(new Runnable() {
@Override
public void run() {
listener.receiveConfigInfo(content);
}
});
}
else {
listener.receiveConfigInfo(content);
}
}
}

return true;
}

@Override
public boolean removeConfig(String dataId, String group) throws NacosException {
String key = createKey(dataId, group);
Expand Down
14 changes: 11 additions & 3 deletions nacos-spring-samples/nacos-embedded-webserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>nacos-spring-parent</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.1.1</version>
<version>${revision}</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -29,12 +29,20 @@
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos.version}</version>
</dependency>


<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>

</dependencies>
</project>
</project>
4 changes: 2 additions & 2 deletions nacos-spring-samples/nacos-spring-webmvc-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>nacos-spring-samples</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.1.1</version>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -82,4 +82,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
4 changes: 2 additions & 2 deletions nacos-spring-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>nacos-spring-parent</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.1.1</version>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -48,4 +48,4 @@
</build>


</project>
</project>
47 changes: 33 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@

<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-spring-parent</artifactId>
<version>1.1.1</version>
<version>${revision}</version>
<name>Alibaba Nacos :: Spring :: POM</name>
<packaging>pom</packaging>



<modules>
<module>nacos-spring-context</module>
<module>nacos-spring-samples</module>
</modules>

<scm>
<url>[email protected]:nacos-group/nacos-spring-project.git</url>
<connection>scm:[email protected]:nacos-group/nacos-spring-project.git</connection>
Expand Down Expand Up @@ -76,6 +75,7 @@
</licenses>

<properties>
<revision>2.0.0</revision>
<argLine>-Dfile.encoding=UTF-8</argLine>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand All @@ -89,11 +89,10 @@
</sonar.jacoco.itReportPath>
<sonar.exclusions>file:**/generated-sources/**,**/test/**</sonar.exclusions>
<!-- Nacos -->
<nacos.version>1.4.1</nacos.version>
<nacos.version>2.2.1</nacos.version>
<!-- Spring -->
<spring.framework.version>3.2.18.RELEASE</spring.framework.version>
<!--snake-yaml-->
<snake.yaml.version>1.19</snake.yaml.version>
<spring.framework.version>5.2.9.RELEASE</spring.framework.version>
<snake.yaml.version>1.29</snake.yaml.version>
<!-- Servlet -->
<servlet-api.version>3.0.1</servlet-api.version>
<!-- javax-->
Expand All @@ -102,6 +101,7 @@
<commons-lang3.version>3.4</commons-lang3.version>
<!-- Alibaba's Spring Context Support -->
<spring-context-support.version>1.0.11</spring-context-support.version>
<slf4j.version>1.7.7</slf4j.version>
</properties>

<!-- 管理依赖版本号,子项目不会默认依赖 -->
Expand All @@ -121,12 +121,6 @@
<version>${nacos.version}</version>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snake.yaml.version}</version>
</dependency>

<!-- Alibaba's Spring Context Support -->
<dependency>
<groupId>com.alibaba.spring</groupId>
Expand Down Expand Up @@ -283,6 +277,31 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down

0 comments on commit e8cae2c

Please sign in to comment.