nacos 源码分析-配置服务

【nacos 源码解析】

  • 目录
    • 概 述
  • 小结
  • 参考资料和推荐阅读

LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code and KPI, Keep progress,make a better result.
Survive during the day and develop at night。

目录

概 述

注册中心:
nacos 源码分析-配置服务_第1张图片
启动入口:
nacos 源码分析-配置服务_第2张图片
配置服务:
启动的Main:

@EnableScheduling
@SpringBootApplication(scanBasePackages = {
        "com.alibaba.nacos.config.server",
        "com.alibaba.nacos.core"})
public class Config {
    
    public static void main(String[] args) {
        SpringApplication.run(Config.class, args);
    }
}

扫描底下的bean.
EnableScheduling定时调度:
先进入控制层:ConfigController:
按照这个为例:catalog在这里插入代码片

  @GetMapping("/catalog")
    @Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
    public RestResult<ConfigAdvanceInfo> getConfigAdvanceInfo(@RequestParam("dataId") String dataId,
            @RequestParam("group") String group,
            @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) {
        ConfigAdvanceInfo configInfo = persistService.findConfigAdvanceInfo(dataId, group, tenant);
        return RestResultUtils.success(configInfo);
    }
    

前台传送一个dataId,group,tenant等。
调用:

 ConfigAdvanceInfo configInfo = persistService.findConfigAdvanceInfo(dataId, group, tenant);
 ConfigAdvanceInfo findConfigAdvanceInfo(final String dataId, final String group, final String tenant);

看下接口的实现:
其中的一个实现:

@Override
    public ConfigAdvanceInfo findConfigAdvanceInfo(final String dataId, final String group, final String tenant) {
        final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
        List<String> configTagList = this.selectTagByConfig(dataId, group, tenant);
        
        ConfigAdvanceInfo configAdvance = databaseOperate.queryOne(
                "SELECT gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,type,c_schema FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=?",
                new Object[] {dataId, group, tenantTmp}, CONFIG_ADVANCE_INFO_ROW_MAPPER);
        
        if (CollectionUtils.isNotEmpty(configTagList)) {
            StringBuilder configTagsTmp = new StringBuilder();
            for (String configTag : configTagList) {
                if (configTagsTmp.length() == 0) {
                    configTagsTmp.append(configTag);
                } else {
                    configTagsTmp.append(',').append(configTag);
                }
            }
            configAdvance.setConfigTags(configTagsTmp.toString());
        }
        return configAdvance;
    }

大概:
//首先进行的意思是:
1.根据dataid 参数
SELECT gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,type,c_schema FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=?"
查询有关配置信息:

2。将配置信息拼成一个字符串返回到控制层。

 return RestResultUtils.success(configInfo);

其他的配置中心包含如下方法:
publishConfig,

getConfig,detailConfigInfo,deleteConfig,getConfigAdvanceInfo,listener,getListeners,等信息。

其他的模块架构也是如此,传统的Spring MVC 式样的请求和处理方式。

小结

参考资料和推荐阅读

1.链接: link

你可能感兴趣的:(spring,cloud,基础教程,java,开发语言)