【发布时间】:2019-01-24 21:19:31
【问题描述】:
我有一个使用 Spring Cloud Config 来刷新其属性的 Spring Boot 应用程序。我可以使用@RefreshScope 轻松刷新我的控制器,但我不确定如何为我的poller 执行相同操作以重新启动我的 Spring 集成工作。
我的 integration-config.xml :
<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>
如果我更改start.task.rate,然后点击/refresh,执行器会检测到更改,但我的poller 没有收到任何内容。有没有办法为它定义某种@RefreshScope?
我的tasky-dev.properties:
start.task.rate=600000
我的应用程序.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>
【问题讨论】:
标签: spring spring-boot spring-integration spring-cloud spring-cloud-config