Kode Charlie
Kode Charlie

Reputation: 1499

SourcePollingChannelAdapter: can inception of polling trigger after application start by arbitrary delay?

Versions:

Spring: 5.2.16.RELEASE
Spring Integrations: 5.3.9.RELEASE
macOS Big Sur: 11.6

For a fuller account of my spring-integration configuration, see this question I posted yesterday.

To sum up, I have set up this channel for polling changes to a directory:

<int-file:inbound-channel-adapter id="channelIn" directory="${channel.dir}" auto-create-directory="false" use-watch-service="false" filter="channelFilter" watch-events="CREATE,MODIFY">
  <int-file:nio-locker ref="channelLocker"/>
  <int:poller fixed-delay="${channel.polling.delay}" max-messages-per-poll="${channel.polling.maxmsgs}"></int:poller>
</int-file:inbound-channel-adapter>

It works fine. However, there does not appear to be a configuration option to start the polling after application-start by some arbitrary delay. In my case, I don't think there is any program error (yet) in starting the polling service immediately after Tomcat container starts my war-file. But it is also true that there is quite a bit going on during the application-start, and my preference would be to defer the inception of the polling service some time after the bean for SourcePollingChannelAdapter is created.

Is there anyway to do this in Spring?

Upvotes: 0

Views: 60

Answers (1)

Gary Russell
Gary Russell

Reputation: 174789

There are (at least) a couple of options:

  1. Instead of fixed-delay, use the trigger property to point to a PeriodicTrigger bean with an initialDelay (and fixedDelay).

  2. Set auto-startup="false" and start the adapter manually either directly, or using a control bus.

https://docs.spring.io/spring-integration/docs/current/reference/html/system-management.html#control-bus

Upvotes: 1

Related Questions