Problems while trying to modify polling rate on runtime using Spring Integration

2.1k views Asked by At

Having defined a channel adapter as:

<int:channel id="target">
    <int:queue /> 
</int:channel>
<int-jdbc:inbound-channel-adapter id="adapter" channel="target" query="${int.poll.query}" update="${int.update.query}" data-source="mock-datasource">
    <int:poller fixed-rate="5000"/>
</int-jdbc:inbound-channel-adapter>

I wonder why I cannot modify the polling rate on runtime, as follows:

SourcePollingChannelAdapter adapter = applicationContext.getBean("adapter",SourcePollingChannelAdapter.class);
adapter.setTrigger(new PeriodicTrigger(1000));

When i debug this solution, I can see that the adapter has this new trigger attached to it, however the polling rate remains unchanged (every 5 secs). I tried also to stop() and start() the adapter, with similar luck.

Anyone can point me out what I am doing wrong? Thanks

2

There are 2 answers

0
user7124 On

[RESOLVED]

It has been confirmed by members of Spring team, that a trigger cannot be modified on runtime. So if you want to modify the polling rate dynamically, for example to throttle inbound messages, you will have to roll your own Trigger implementation and add a setter for the interval polling.

I leave here the changes done in my configuration:

<int-jdbc:inbound-channel-adapter id="bancsAdapter" channel="target" query="${int.bancs.poll.query}" update="${int.bancs.update.query}" data-source="bancsMockDB">
    <int:poller trigger="dynamicTrigger" />
</int-jdbc:inbound-channel-adapter>

<bean id="dynamicTrigger" class="directlabs.integration.DynamicTrigger">
    <constructor-arg value="5000" />
</bean>

So for throttling, you only need to do the following:

applicationContext.getBean("dynamicTrigger",DynamicTrigger.class).setPeriod(1000);

The implementation of the DynamicTrigger can be found here

The original comments from the Spring team members can be found here.

0
Stephen McConnell On

While space here does not allow for a full example, we created a Service that uses Quartz Scheduler as a triggering mechanism. It accepts an XML document with the Quartz Jobs and Triggers defined (this stack overflow describes the process Use simple xml to drive the Quartz Sheduler )

The input channel will accept the XML to be used for setting the Schedules in Quartz. The input channel then can be used to accept dynamic updates of jobs and triggers.

The xml entries in the job-map-data will have an "output" channel defined and one can add other job-map-data that can be set in the output message header to allow for routing.

We constantly re-use this Service in many of our Spring Integration contexts.

Hope this helps.