redAce
redAce

Reputation: 1798

How to refresh spring integration poller with @RefreshScope?

I have a Spring Boot application that uses Spring Cloud Config to refresh its properties. I can easily refresh my controllers with @RefreshScope but I'm not sure how I can do the same for my poller to restart my Spring Integration job.

My 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>

If I change start.task.rate, then hit /refresh, the actuator detects the change but nothing is picked up by my poller. Is there any way to define some sort of @RefreshScope for it ?

My tasky-dev.properties :

start.task.rate=600000

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);
    }

}

=======

Update :

Attempting Artem's solution with setting a PeriodicTrigger. The scope is refreshed but only when the poller is recalled (once the fixedRate duration has passed):

@RefreshScope
@Bean
public PeriodicTrigger refreshablePeriodicTrigger() {
    PeriodicTrigger periodicTrigger = new PeriodicTrigger(fixedRate);
    periodicTrigger.setFixedRate(true);
    return periodicTrigger;
}

And :

<int:inbound-channel-adapter ref="tasksService" method="requestAllTasks" channel="initTimestampChannel">
    <int:poller trigger="refreshablePeriodicTrigger"></int:poller>
</int:inbound-channel-adapter>

Upvotes: 1

Views: 734

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121282

Well, that convenient <poller> registers essentially a Trigger object to be used by the TaskScheduler.schedule(Runnable task, Trigger trigger).

What I can suggest you is to register a PeriodicTrigger bean in some @Configuration with @RefreshScope and use it in the <poller> definition instead of fixed-rate property.

Upvotes: 1

Related Questions