Disconf实时更新配置文件实测

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分钟

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值