如何使用@RefreshScope刷新spring集成轮询器?
我有一个SpringBoot应用程序,它使用SpringCloudConfig刷新其属性。我可以很容易地用@RefreshScope刷新我的控制器,但我不确定如何让轮询器重新启动我的Spring集成作业 My integration-config.xml:如何使用@RefreshScope刷新spring集成轮询器?,spring,spring-boot,spring-integration,spring-cloud,spring-cloud-config,Spring,Spring Boot,Spring Integration,Spring Cloud,Spring Cloud Config,我有一个SpringBoot应用程序,它使用SpringCloudConfig刷新其属性。我可以很容易地用@RefreshScope刷新我的控制器,但我不确定如何让轮询器重新启动我的Spring集成作业 My integration-config.xml: <context:property-placeholder location="file:///C:/workspace/config/tasky-dev.properties" /> <int:inbound-chann
<context:property-placeholder location="file:///C:/workspace/config/tasky-dev.properties" />
<int:inbound-channel-adapter ref="tasksService" method="requestAllTasks" channel="initTimestampChannel">
<int:poller fixed-rate="${start.task.rate}"></int:poller>
</int:inbound-channel-adapter>
My Application.java:
@SpringBootApplication
@EnableConfigServer
@ImportResource("classpath:integration-config.xml")
@EnableSwagger2
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
=======
更新:
试图通过设置PeriodicTrigger来实现Artem的解决方案。范围刷新,但仅当轮询器在fixedRate持续时间过后被调用时:
@RefreshScope
@Bean
public PeriodicTrigger refreshablePeriodicTrigger() {
PeriodicTrigger periodicTrigger = new PeriodicTrigger(fixedRate);
periodicTrigger.setFixedRate(true);
return periodicTrigger;
}
以及:
<int:inbound-channel-adapter ref="tasksService" method="requestAllTasks" channel="initTimestampChannel">
<int:poller trigger="refreshablePeriodicTrigger"></int:poller>
</int:inbound-channel-adapter>
好的,这实际上是一个触发器对象,由TaskScheduler使用。scheduleRunnable任务,触发器触发器
我建议您在@RefreshScope的@Configuration中注册PeriodicTrigger bean,并在定义中使用它,而不是在固定费率属性中使用它。我已经更新了我的帖子。这几乎就是我想要做的。使用您的解决方案,范围会被刷新,但只有当轮询器在fixedRate持续时间过后被调用时,我才能在fixedRate刷新时立即重新初始化RefreshAblePeriodicRigger?好的,您可以在刷新期间停止,但正在进行的任务无论如何都会完成。感谢您的回答。我终于意识到,我所做的一切都适得其反,我的XML中至少有20个其他元素使用属性,我需要对它们中的每一个都做同样的事情。如果我想刷新我的bean,那么切换到JavaDSL配置将更加容易和干净。我以为会有一些Spring集成的神奇药丸,可以让我的所有bean直接从XML中刷新。。。不幸的是,事实并非如此。XML被解析为一组bean,在运行时,我们有一个与XMLDSL稍有不同的模型。此外,RefreshScope在XML配置之后很久才引入,看起来它是为Java配置而设计的
<int:inbound-channel-adapter ref="tasksService" method="requestAllTasks" channel="initTimestampChannel">
<int:poller trigger="refreshablePeriodicTrigger"></int:poller>
</int:inbound-channel-adapter>