其实我们发现在我们本地新生成了文件,这个文件就是nacos;

这个文件怎么那么眼熟,不就是我们的controller中的注解里面的参数value么;

@Controller
@NacosPropertySource(dataId = "springboot2-nacos-config", autoRefreshed = true)
public class HealthController {
@Autowired
private String healthString;
    @NacosValue(value = "${nacos.test.propertie:123}", autoRefreshed = true)
private String testProperties;

这个文件的内容我们看看呢

还真是跟我们的注解value的key是一样的,我们在nacos中每做一次修改这个值都会关联的改动,

而且我们直接把这个值改了,显示的依然还是nacos中的值,所以我们可以大胆预测,nacos修改配置值之后会联动改配置文件中的值,

但是取值还是根据缓存中的值来的,可能就是某个map或者其他的存储形式,肯定我们是在哪里漏了,我们继续go

其实,这块代码我们有看到过,只不过没有在意,上代码:

static public boolean dump(String dataId, String group, String tenant, String content, long lastModifiedTs) {
String groupKey = GroupKey2.getKey(dataId, group, tenant);
makeSure(groupKey);
final int lockResult = tryWriteLock(groupKey);
assert (lockResult != 0); if (lockResult < 0) {
dumpLog.warn("[dump-error] write lock failed. {}", groupKey);
return false;
} try {
final String md5 = MD5.getInstance().getMD5String(content);
if (md5.equals(ConfigService.getContentMd5(groupKey))) {
dumpLog.warn(
"[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}",
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
} else if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
DiskUtil.saveToDisk(dataId, group, tenant, content);
}
updateMd5(groupKey, md5, lastModifiedTs);
return true;
} catch (IOException ioe) {
dumpLog.error("[dump-exception] save disk error. " + groupKey + ", " + ioe.toString(), ioe);
if (ioe.getMessage() != null) {
String errMsg = ioe.getMessage();
if (NO_SPACE_CN.equals(errMsg) || NO_SPACE_EN.equals(errMsg) || errMsg.contains(DISK_QUATA_CN)
|| errMsg.contains(DISK_QUATA_EN)) {
// 磁盘写满保护代码
fatalLog.error("磁盘满自杀退出", ioe);
System.exit(0);
}
}
return false;
} finally {
releaseWriteLock(groupKey);
}
}

上面标红的代码就是把我们跟新的配置存储到文件里面去;好了 一个闭环的来龙去脉基本清楚了,至于里面很多的其他逻辑

我感觉都是后面迭代打补丁上去的,主干的东东就这么多了;下面我们继续看,因为我们这个nacos跟client都是在windows下debug的

究竟保存的文件是保存到客户端还是nacos的,其实自己仔细想想应该就能知道了,嘿嘿,先卖个关子,下集我们继续,go!!

Nacos深入浅出(六)的更多相关文章

  1. Nacos深入浅出(十)

    基本上到第9篇,整个请求的一套就结束了,感觉这里跳跳绕绕很多东西,下面我们来做个总结:从Nacos配置平台修改,到Client请求更新,事件触发去取值返回给客户端,整个过程感觉只分析到了4.5层的深度 ...

  2. Nacos深入浅出(九)

    然而Nacos的发布操作并不是上面我们想的那样通过代理去实现,通过下面的代码我们分析下: public class NacosConfigurationPropertiesBindingPostPro ...

  3. Nacos深入浅出(八)

    Nacos-spring-context.java 感觉这个后台要比之前的Nacos复杂多了,涉及到很多基础的概念,慢慢看,这个后面慢慢更新解析过程 看到他的目录结构一个是基于注解,一个是XML的解析 ...

  4. Nacos深入浅出(七)

    大家可以把这个也下载下来,结合之前的Nacos一起来看下,感觉前面几篇看了好像冰山一角的感觉 学无止境! https://github.com/nacos-group/nacos-spring-pro ...

  5. Nacos深入浅出(五)

    四中标色的代码 result = ConfigService.dump(dataId, group, tenant, cf.getContent(), lastModified); 我们看下这个方法 ...

  6. Nacos深入浅出(四)

    private void executeAsyncInvoke() { while (!queue.isEmpty()) { NotifySingleTask task = queue.poll(); ...

  7. Nacos深入浅出(二)

    如果你的服务已经能正常跑起来,个人建议可以先感受下nacos的魅力,也就是怎么使用吧 直接上代码 @Controller @NacosPropertySource(dataId = "spr ...

  8. Nacos深入浅出(一)

    Nacos代码第一次给我的感觉有点小清新,下面就带大家抽丝剥茧看看源代码,看看阿里大神的东东: 建议大家先把Nacos跑起来,网上有很多教程,最好直接去git里面拉代码,在IDEA里面运行: cons ...

  9. Nacos(六):多环境下如何“管理”及“隔离”配置和服务

    前言 前景回顾: Nacos(五):多环境下如何"读取"Nacos中相应环境的配置 Nacos(四):SpringCloud项目中接入Nacos作为配置中心 现如今,在微服务体系中 ...

随机推荐

  1. 使用C++模拟C#的委托机制

    1. [代码][C/C++]代码 //Event.h  #ifndef _EVENT_H_#define _EVENT_H_class EmptyObject {};template<typen ...

  2. aop 例子(annotation方式实现)

    面向切面编程(也叫面向方面),可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术.AOP实际是GoF设计模式的延续,设计模式孜孜不倦追求的是调用者和被调用者之 ...

  3. 浅析linux 下shell命令执行和守护进程

    执行shell脚本有以下几种方式 1.相对路径方式,需先cd到脚本路径下 [root@banking tmp]# cd /tmp [root@banking tmp]# ./ceshi.sh 脚本执行 ...

  4. OpenCV——PS滤镜算法之 球面化 (凹陷效果)

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  5. [C++11新特性]第二篇

    0.可变数量参数,可变函数模版,变长模版类 c++98可变数量参数 #include<cstdio> #include<cstdarg> double SumOfFloat(i ...

  6. 使用svg的几种方式

    <!-- 图片,背景,框架引入svg文件 --> <img src="test.svg" alt=""> <?xml versio ...

  7. 集训Day2

    雅礼集训2017Day2 T1 给你一个水箱,水箱里有n-1个挡板,水遵循物理定律 给你m个条件,表示第i个格子上面y+1高度的地方有或没有水 现在给你无限的水从任意地方往下倒,问最多满足多少条件 n ...

  8. 1131 Subway Map(30 分)

    In the big cities, the subway systems always look so complex to the visitors. To give you some sense ...

  9. AngularJs(Part 1)

    I am tired to translate these into Chinese. but who cares? i write these posts just for myself Scope ...

  10. Will&nbsp;you&nbsp;still&nbsp;need&nbsp;me?

    ON FRIDAY, the National Bureau of Statistics announced that China's working-age population shrank la ...