Netflix Archaius分布式配置管理依赖构件

  

Archaius配置管理API,包含一系列配置管理API,提供动态类型化属性,线程安全配置操作,轮询框架,回调机制等功能。

概述

Archaius是Netflix公司开源项目之一,基于java的配置管理类库,主要用于多配置存储的动态获取。主要功能是对apache常见配置类库的扩展。在云平台开发中可以将其用作分布式配置管理依赖构件,同时,它有如下一些特性:

<李>

动态类型化属性

<李>

高效和线程安全的配置操作

<李>

配置改变时的回调机制

<李>

轮询框架

<李>

JMX,通过Jconsole检查和调用操作属性

<李>

组合配置

 Netflix Archaius分布式配置管理依赖构件

p_w_picpath。png

适用场景

对于传统的单体应用,属性等配置文件可以解决配置问题,同时也可以通过maven配置配置来区别各个环境,但在一个几百上千节点的的微服务生态中,微服务采用多种语言开发,配置文件格式多样,如何把每个微服务的配置文件都进行更新,并且很多时候还需要重启服务,是一件无法忍受的事情,所以,对于微服务架构而言,一个通用的配置中心是必不可少的。

新接口逻辑上线,老接口面临迁移,开发测试完成后,马上要上线。但是接口调用发的研发同学对新接口的稳定性,性能存在一定的质疑,为了避免风险,要求可以上线后紧急切换回老接口。这时候我们就需要一个手动开关,所以对于类似需求,一个通用的配置中心是必不可少的。

Archaius提供的DynamicIntProperty类可以在配置发生变化时动态地获取配置,并且不需要重启应用,而底层的配置存储,建议使用管理员进行存储,Archaius作为客户端的类库使用。

代码案例

引入依赖

& lt; dependency>   ,,,& lt; groupId> com.netflix.archaius   ,,,& lt; artifactId> archaius-core   & lt;/dependency>

自定义配置

PropertiesConfiguration
public  class  PropertiesConfiguration  extends  DynamicConfiguration  {   ,,,private  static  final  Logger  Logger =, LoggerFactory.getLogger (PropertiesConfiguration.class);   ,,,private  static  final  int  INITIAL_DELAY_MILLIS =, 0;   ,,,private  static  final  int  DELAY_MILLIS =, 60, *, 1000;   ,,,private  static  final  boolean  IGNORE_DELETES_FROM_SOURCE =,真的;      ,,,public  PropertiesConfiguration (String  confDir), {   ,,,,,,,这(new  String [] {confDir});   ,,,}      ,,,public  PropertiesConfiguration (final 字符串…confDirs), {   ,,,,,,,String [], propertiesPaths =, Lists.newArrayList (Iterables.concat (Iterables.transform (arrays . aslist (confDirs), new  Function<字符串,List在(),{   ,,,,,,,,,,@Nullable   ,,,,,,,,,,@Override   ,,,,,,,,,,,public  List,应用(String  confDir), {   ,,,,,,,,,,,,,,,Assert.isTrue (new 文件(confDir) .isDirectory (),, StringUtil.format(“路径({})无法查找(. properties)文件”,,confDirs));   ,,,,,,,,,,,,,,,String [], propertiesPaths =, getPaths (confDir);   ,,,,,,,,,,,,,,,if  (ArrayUtils.isNotEmpty (propertiesPaths)), {   ,,,,,,,,,,,,,,,,,,,return  Lists.newArrayList (propertiesPaths);   ,,,,,,,,,,,,,,,},{else    ,,,,,,,,,,,,,,,,,,,   ,,,,,,,,,,,,,,,,,,,return  Lists.newArrayList ();   ,,,,,,,,,,,,,,,}   ,,,,,,,,,,,}   ,,,,,,,}))).toArray (new 字符串[0]);   ,,,,,,,if  (ArrayUtils.isNotEmpty (propertiesPaths)), {   ,,,,,,,,,,,super.startPolling (new  URLConfigurationSource (propertiesPaths), new  FixedDelayPollingScheduler (INITIAL_DELAY_MILLIS, DELAY_MILLIS,, IGNORE_DELETES_FROM_SOURCE));   ,,,,,,,}   ,,,,,,,ConfigurationLog.successInit (PropertiesConfiguration.class, this.getProperties ());   ,,,}      ,,,private  static  String [], getPaths (String  confDir), {   ,,,,,,,try  {   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

Netflix Archaius分布式配置管理依赖构件