ark
ark

Reputation: 167

How to dynamically change the poller cron for InboundChannelAdapter in spring integration

I've looked around a lot, this is my configuration, how can I change the poller cron dynamically? As in, when the application is running and I change the poller cron in the db it should be picked up by the Poller in the InboundChannelAdapter.

Note: I don't use spring cloud config so @RefreshScope is not really an option

@Bean
@InboundChannelAdapter(channel = "sftpStreamChannel", poller = @Poller(cron = "${pollerCron}", maxMessagesPerPoll = "-1"))
public MessageSource<InputStream> sftpMessageSource()
{
    SftpStreamingMessageSource source = new SftpStreamingMessageSource(template());
    source.setRemoteDirectory(sftpRemoteDirectory);
    source.setFilter(abSftpFileFilter());
    return source;
}

Upvotes: 0

Views: 1299

Answers (1)

Gary Russell
Gary Russell

Reputation: 174544

You cannot change the cron expression dynamically; the framework does provide a DynamicPeriodicTrigger which can be used to change the fixed-delay or fixed-rate at runtime (but the change doesn't take effect until the next poll).

You might also find that a smart poller might be suitable for your use case - see "Smart" Polling, where the poller can make decisions about whether or not to proceed with a poll.

You could also create your own Trigger that wraps a CronTrigger and delegate to it; that would allow you to change it at runtime. But, again, changes won't take effect until the next poll.

Upvotes: 1

Related Questions