繁体   English   中英

如何使用@RefreshScope刷新Spring Integration Poller?

[英]How to refresh spring integration poller with @RefreshScope?

我有一个使用Spring Cloud Config刷新其属性的Spring Boot应用程序。 我可以使用@RefreshScope轻松地刷新控制器,但是我不确定如何才能使我的poller重新启动Spring Integration作业。

我的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

我的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>

好吧,方便的<poller>本质上注册了一个TaskScheduler.schedule(Runnable task, Trigger trigger)使用的Trigger对象TaskScheduler.schedule(Runnable task, Trigger trigger)

我建议您使用@RefreshScope在某个@Configuration注册一个PeriodicTrigger bean,并在<poller>定义中使用它,而不是使用fixed-rate属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM