阿波罗分布式配置中心

2020-10-29  本文已影响0人  liangxifeng833

执行流程

image.png image.png image.png

工作原理:

发布配置原理:

image.png

各个模块和职责

image.png

环境搭建

基础环境要求:

jdk1.8, mysql数据库建议5.7以上版本,低于5.7版本数据库默认不支持一个表中有两个时间时间戳timestamp类型字段的.如果是虚拟机安装虚拟内存>2G;
apollo-build-scripts-master 整个阿波罗环境包,使用一个命令启动整个阿波罗环境.
appollo-master 源码和依赖包,建议打包到master本地仓库.

创建两个数据库:
apolloconfigdb 存放配置文件信息数据.
apolloportaldb 存放阿波罗管理后台信息数据
* 参考搭建文章: Apollo配置中心搭建 & SpringBoot整合Apollo客户端

SpringBoot整合Apollo客户端实现从配置中心读取配置信息及配置中心更改配置后通知客户端实时更新

    unzip apollo-master.zip
    cd apollo-master/scripts
    ./build.sh
  local.meta=http://127.0.0.1:8080
  dev.meta=http://127.0.0.1:8080
  fat.meta=${fat_meta}
  uat.meta=${uat_meta}
  lpt.meta=${lpt_meta}
  pro.meta=${pro_meta}
  package apolloClient;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
//@EnableEurekaClient 将当前服务注册到Eureka
@EnableEurekaClient
//启用apollo客户端
@EnableApolloConfig
public class ApolloClientApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(ApolloClientApplication.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ApolloClientApplication.class);
    }
}
package apolloClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
    //这里是读取配置中心里面的自定义name属性,如果没有查询到name值默认=test
    @Value("${name:test}")
    String name;

    @GetMapping("apollo")
    public String getName() {
        return name;
    }
}

点击查看测试代码

上一篇 下一篇

猜你喜欢

热点阅读