linux阿波罗配置文件放在哪,Apollo阿波罗配置中心
一、准备工作
1.2.1 AppId classpath:/META-INF/app.properties 内容app.id=YOUR-APP-ID
1.2.2 Environment 对于Mac/Linux,文件位置为/opt/settings/server.properties 例如env=DEV 详细见文档。
1.2.3 本地缓存路径 /opt/data/{appId}/config-cache (权限)
二、Maven Dependency
com.ctrip.framework.apollo
apollo-client
0.7.0
三、客户端用法
3.1 API使用方式
Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null
String someKey = "someKeyFromDefaultNamespace";
String someDefaultValue = "someDefaultValueForTheKey";
String value = config.getProperty(someKey, someDefaultValue);3.1.2 监听配置变化事件
Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null
config.addChangeListener(new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
System.out.println("Changes for namespace " + changeEvent.getNamespace());
for (String key : changeEvent.changedKeys()) {
ConfigChange change = changeEvent.getChange(key);
System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType()));
}
}
});3.1.3 获取公共Namespace的配置
String somePublicNamespace = "CAT";
Config config = ConfigService.getConfig(somePublicNamespace); //config instance is singleton for each namespace and is never null
String someKey = "someKeyFromPublicNamespace";
String someDefaultValue = "someDefaultValueForTheKey";
String value = config.getProperty(someKey, someDefaultValue);3.2 Spring整合方式
3.2.1 基于XML的配置
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:apollo="http://www.ctrip.com/schema/apollo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd">
3.2.3 Spring Annotation支持
Apollo同时还增加了两个新的Annotation来简化在Spring环境中的使用。
@ApolloConfig
用来自动注入Config对象
@ApolloConfigChangeListener
用来自动注册ConfigChangeListener
public class TestApolloAnnotationBean {
@ApolloConfig
private Config config; //inject config for namespace application
@ApolloConfig("application")
private Config anotherConfig; //inject config for namespace application
@ApolloConfig("FX.apollo")
private Config yetAnotherConfig; //inject config for namespace FX.apollo
@Value("${batch:100}")
private int batch;
//config change listener for namespace application
@ApolloConfigChangeListener
private void someOnChange(ConfigChangeEvent changeEvent) {
//update injected value of batch if it is changed in Apollo
if (changeEvent.isChanged("batch")) {
batch = config.getIntProperty("batch", 100);
}
}
//config change listener for namespace application
@ApolloConfigChangeListener("application")
private void anotherOnChange(ConfigChangeEvent changeEvent) {
//do something
}
//config change listener for namespaces application and FX.apollo
@ApolloConfigChangeListener({"application", "FX.apollo"})
private void yetAnotherOnChange(ConfigChangeEvent changeEvent) {
//do something
}
//example of getting config from Apollo directly
//this will always return the latest value of timeout
public int getTimeout() {
return config.getIntProperty("timeout", 200);
}
//example of getting config from injected value
//the program needs to update the injected value when batch is changed in Apollo using @ApolloConfigChangeListener shown above
public int getBatch() {
return this.batch;
}
}转载文章:
Apollo配置
linux阿波罗配置文件放在哪,Apollo阿波罗配置中心相关推荐
- Apollo微服务配置中心详解
Apollo微服务配置中心详解 前言 一.Apollo架构 (一)简介 (二)角色介绍 (三)服务端实现 (四)客服端实现 二.Apollo部署 (一)准备数据库 (二)配置服务 1. 手动部署 (1 ...
- .NET Core + K8S + Apollo 玩转配置中心
1.引言 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用于微服务配置管理 ...
- Apollo(分布式配置中心)核心概念及核心功能介绍
Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用于微服务配置管理场景. 服 ...
- Java基础学习总结(181)——Nacos、Apollo、Config配置中心如何选型?
1.为什么需要配置中心 1.配置实时生效 传统的静态配置方式要想修改某个配置只能修改之后重新发布应用,要实现动态性,可以选择使用数据库,通过定时轮询访问数据库来感知配置的变化.轮询频率低感知配置变化的 ...
- Apollo - 阿波罗配置中心使用,一文搞定!
Apollo基本概念 一.简介 Apollo - A reliable configuration management system Apollo的Github地址 Apollo(阿波罗)是携程框架 ...
- springcloud分布式配置中心(二)-阿波罗apollo
1.Springcloud的分布式配置中心组件 组件一般有两个,springcloud config,apollo.apollo有一个好处是apollo有界面,这是apollo的一个优势. sprin ...
- Apollo阿波罗配置中心基本概述
1.什么是Apollo: Apollo(阿波罗)是一款可靠的分布式配置管理中心,诞生于携程框架研发部,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流 ...
- Apollo-阿波罗配置中心详细使用教程
Apollo基本概念 一.简介 Apollo - A reliable configuration management system Apollo的Github地址 Apollo(阿波罗)是携程框架 ...
- 微服务 分布式配置中心Apollo详解
微服务 分布式配置中心Apollo详解 1. 配置中心概述 1.1 配置中心简介 1.2 配置中心特点 1.3 配置中心对比 2. Apollo概述 2.1 Apollo简介 2.2 Apollo特点 ...
最新文章
- php最常见代码,PHP常见算法合集代码实例
- 关于istringstream用法的一个坑
- django-连接数据库mysql
- java 二维数组奇数金字塔_调整数组顺序使得奇数在前偶数在后(Java)
- 权限设计表结构超详细_模具设计丨问题点检表、全套标准件结构分布,值得转发...
- 项目练习(二)—微博数据结构化
- 第9章 互相作用的圆球 (《Python趣味创意编程》教学视频)
- 剑指offer——面试题57:删除链表中重复的结点
- 设计模式-软件设计七大原则
- cent OS 6.3 yum方式安装openldap,phppldapadmin,lam
- 织梦友情链接html,总结dedecms怎么调用友情链接的方法[全]
- 加码游戏直播 快手已成腾讯防御今日头条的重要棋子?
- 电工与电子技术基础【1】
- ArcGIS for Android 100.3的学习与应用(三) 实现地图添加自定义指北针
- 走向面试之数据库基础:一、你必知必会的SQL语句练习-Part 2
- VIOS查看网卡对应的插槽
- 1919: kirito's 星爆气流斩(多重背包转换为01背包+二进制优化)
- 对互联网VC的10点看法
- 【react】This synthetic event is reused for performance reasons.
- 查询 maven 依赖 的最新版本号