Announcement Announcement Module
No announcement yet.
Problems while trying to modify polling rate on runtime Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems while trying to modify polling rate on runtime

    Hi all,

    Having defined a channel adapter as:
      <int:channel id="target">
    	<int:queue />
       <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"/>
    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?

  • #2
    Any reason why you want to modify the polling rate?


    • #3
      As a way to throttle inbound messages. I know that there are other ways to achieve this, however I wanted to know why you cannot modify this property on runtime.


      • #4
        Under the covers we are simply creating a PeriodicTrigger instance (it is defined in the Spring Framework core), and it accepts the "interval" as a constructor argument. Therefore it cannot be changed at runtime. However, you can define your own implementation of the Trigger interface, even using the PeriodicTrigger as a starting point. Then, you could add a setter for the interval (or even embed your throttling logic within the trigger itself if possible). Then, the interval can be changed between polls. It will be used with each call to nextExecutionTime (to schedule the next poll), so that should have the desired effect. To use your poller, remove the 'fixed-rate' attribute from your poller element and add a 'trigger' attribute referencing your instance instead. In other words, you would provide a Trigger that has dynamic capabilities itself rather than changing the Trigger reference at runtime.

        Hope that helps.


        • #5
          Going back to you original post, you CAN modify it if you implement your own Trigger and set it on the poller via 'trigger' attribute. You can than expose properties on the this custom Trigger implementation that allow you to change how the next execution time is calculated.
          public interface Trigger {
          	Date nextExecutionTime(TriggerContext triggerContext);
          Trigger is a very simple strategy (as yo can see from above) that defines only one method which is invoked by scheduler after each successful invocation of the task. What happens and how it happens in the Trigger.nextExecutionTime(..) is entirely up to the implementation.


          • #6
            I have created a Jira to document this requirement in the reference manual: