Announcement Announcement Module
Collapse
No announcement yet.
Database polling and interval trigger Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Database polling and interval trigger

    Fairly new to Spring Integration and I've read documentation and several threads on using Spring Integration and polling a database (and then doing something afterwards).

    What I would like to do is to poll a "queue table" in a database in a multi-threaded manner such that as more items exist in the queue table more polling threads are created to go after the new work. So, this seems to be handled with a Poller from Spring Integration and a Task Executor from the Spring framework. Here's the struggle though... when I do something like this with 100 items in my queue table:

    Code:
    <integration:poller id="somePoller" task-executor="someExecutor"
       max-messages-per-poll="1">
       
          <integration:interval-trigger interval="100" 
              time-unit="MILLISECONDS" />
              
    </integration:poller>
    
    <task:executor id="someExecutor" pool-size="5-100" queue-capacity="5"/>
    it works as I would want it to, where work is being pulled from the queue table and being handled by several different threads at once. The downside to this, however, is that once I exhaust all the rows in the queue table, I don't really want it pounding away at my database every 100 milliseconds looking for more work to do. What I'd really rather do is something like this:

    Code:
    <integration:poller id="somePoller" task-executor="someExecutor"
       max-messages-per-poll="1">
       
          <integration:interval-trigger interval="5" 
              time-unit="SECONDS" />
              
    </integration:poller>
    
    <task:executor id="someExecutor" pool-size="5-100" queue-capacity="5"/>
    but this doesn't work for me either because it polls once, finds an item, waits 5 seconds, polls again, and so on and so forth. What I really want it to do is to spin up a pool of threads when it has lots of work to do and then go back to sleeping and polling on 5 second intervals. Is there a simple mechanism for doing this?

  • #2
    Hi

    What I really want it to do is to spin up a pool of threads when it has lots of work to do and then go back to sleeping and polling on 5 second intervals.
    That would be great But someone/something has to check (in database) whether there is some work to do...

    But you've already used the required mechanism - max-messages-per-poll="1". Try increasing this amount and increase the interval.

    The second option is to write your own poller which can be adjusted at runtime. Actually the poller is invoked by org.springframework.scheduling.TaskScheduler so you should configure the trigger which controls the invocation of Poller's Runnable. If you detect there is nothing to do, you should (somehow) reconfigure (actually restart - doStop / doStart) AbstractPollingEndpoint with new polling interval.

    regards
    Grzegorz Grzybek

    Comment


    • #3
      How to set Poller interval &amp; max-rows per poll as dynamic values

      Hi All,

      I am very new to spring integration . I have used spring-integration-2.1 for my code.

      I created a database poller which will query a particular table and update the status at some custom poller interval .

      I am using eclipse as my IDE and i wrote the application context.xml and configured the poller implemetation inside an in-bound-channel adapter.

      Now my application context xml will look like


      <jdbc:inbound-channel-adapter id="InboundMessage_Order_DB_Poller"
      query="select * from T_OM_ORDER_TRANS_DTLS where STATUS='NEW' and POLL_STATUS='N'"
      channel="inboundChannel_Order_DB_Poller" data-source="dataSource"
      update="update T_OM_ORDER_TRANS_DTLS set STATUS='RECEIVED' , POLL_STATUS='Y' where ROW_ID in (:ROW_ID)"
      max-rows-per-poll="#{jdbcDatabaseDAO.maxRowsPerPoll}">
      <poller trigger="periodicTrigger">
      <transactional isolation="DEFAULT" />
      </poller>
      </jdbc:inbound-channel-adapter>
      and i set poller interval =40000 ms & max-rows-per-poll=4 in the table . I query a table and get the

      poller interval & max-rows-per-poll.

      When i run the appliaction , i change the values to poller interval =50000 ms & max-rows-per-poll=2 .


      But the new values wont take effect until i restart the server..


      Now the question comes up in my mind,

      Is there any way to set the poller interval & max-rows-per-poll in runtime without restarting the server?

      Can someone help to solve this ?
      Last edited by velsamybe; Dec 17th, 2012, 12:37 AM.

      Comment

      Working...
      X