Disconf支持实时更新配置文件 实际是否支持要看具体的配置(项目中使用注解还是xml)
服务端(服务器):Disconf配置文件更新 ,Disconf-web通知模块实时通知使用这些配置的所有实例 去重新下载这些文件 ;
客户端(具体项目):如果使用注解实现的可以实时生效 而xml的方式需要自己reload到bean里面。
实测实时自动加载配置文件,并更新到Bean中
采用的是定时任务,每分钟执行一次
(1)disconf.xml
<bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
destroy-method="destroy">
<property name="scanPackage" value="com.kltong.quartz.config"/>
</bean>
<bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond"
init-method="init" destroy-method="destroy">
</bean>
(2)Test.properties
testReload=我是启动加载
#testReload=我是实时自动加载
(3)TestProperties
@Component
@DisconfFile(filename = "Test.properties")
public class TestProperties {
private String testReload;
@DisconfFileItem(name = "testReload")
public String getTestReload() {
return testReload;
}
public void setTestReload(String testReload) {
this.testReload = testReload;
}
}
(4)定时任务HelloJob
public class HelloJob implements BaseJob {
private static Logger _log = LoggerFactory.getLogger(HelloJob.class);
/*
* public HelloJob() {
*
* }
*/
@Autowired
private TestProperties testProperties;
public void execute(JobExecutionContext context) throws JobExecutionException {
_log.error("Hello Job执行时间: " + new Date());
System.err.println(testProperties.getTestReload());
}
}
(5)测试结果
[main-EventThread] com.baidu.disconf.client.watch.inner.NodeWatcher[86]:============GOT UPDATE EVENT WatchedEvent state:SyncConnected type:NodeDataChanged path:/disconf/ma-quartz_1.0_test/file/Test.properties: (/disconf/ma-quartz_1.0_test/file/Test.properties,Test.properties,配置文件)======================
Disconf支持实时更新配置文件 (配置的文件及字段要采用注解注入方式):且延迟小于1分钟