title: spring integration poller vs dispatcher
body: <p>I am trying to setup a simple application using spring integration. The goal is to simply use a file inbound channel adapter to monitor a directory for new files and process files as they are added. For simplicity the processing the files at the moment is simply logging some output (name of file being processed). I do however want to process files in a multithreaded fashion. So lets say 10 files are picked up and should be processed in parallel and once these are completed only then we move on to the next 10 files.</p>
  
  <p>For that I tried two different approaches and both seem to work similarly and I wanted to understand the differences between using poller or dispatcher for something like this.</p>
  
  <p>Approach #1 - Using poller</p>
  
  <pre><code>&lt;int-file:inbound-channel-adapter id="filesIn" directory="in"&gt;
          &lt;int:poller fixed-rate="1" task-executor="executor" /&gt;
  &lt;/int-file:inbound-channel-adapter&gt;
  
  &lt;int:service-activator ref="moveToStage" method="move" input-channel="filesIn" /&gt;
  
  &lt;task:executor id="executor" pool-size="5" queue-capacity="0" rejection-policy="DISCARD" /&gt;
  </code></pre>
  
  <p>So here the idea as I understand is that we are constantly polling the directory and as soon as a file is received its sent to filesIn channel until the pool limit is reached. Then until the pool is occupied no additional files are sent even though im assuming the polling still continues in the background. This seems to work but I am not sure if using the max messages per poll can be helpful here to decrease the polling frequency. By setting the max messages per poll close to pool size.</p>
  
  <p>Approach #2 - Using dispatcher</p>
  
  <pre><code>&lt;int-file:inbound-channel-adapter id="filesIn" directory="in"&gt;
      &lt;int:poller fixed-rate="5000" max-messages-per-poll="3" /&gt;
  &lt;/int-file:inbound-channel-adapter&gt;
  
  &lt;int:bridge input-channel="filesIn" output-channel="filesReady" /&gt;
  
  &lt;int:channel id="filesReady"&gt;
      &lt;int:dispatcher task-executor="executor"/&gt;
  &lt;/int:channel&gt;
  
  &lt;int:service-activator ref="moveToStage" method="move" input-channel="filesInReady" /&gt;
  
  &lt;task:executor id="executor" pool-size="5" queue-capacity="0" rejection-policy="CALLER_RUNS" /&gt;
  </code></pre>
  
  <p>okay so here the poller is not using the executor so I am assuming its polling in a sequential fashion. Every poll 3 files should be picked up and then sent to filesReady channel which then uses the dispatcher to pass the files on to the service activator and because it uses the executor for dispatcher it immediately returns control and allows the filesIn channel to send more files.</p>
  
  <p>I guess my question is am I understanding both approaches correctly and if one is better than other.</p>
  
  <p>Thanks</p>