title: Mule - VM endpoint isn't processing messages in order
body: <p>I'm trying to process large CSV files (250k+ rows x 6 columns) in Mule. Using <a href="https://stackoverflow.com/questions/16395665/how-to-read-huge-csv-file-in-mule">this question</a> as guidance, I've put together the following flow:</p>
  
  <pre><code>&lt;!-- File Connectors --&gt;
  &lt;file:connector name="FileConnector" workDirectory="..." autoDelete="false" streaming="true" doc:name="File"/&gt;
  
  &lt;flow name="mainFlow" doc:name="mainFlow" processingStrategy="synchronous"&gt;
  
      &lt;file:inbound-endpoint name="FileEndpoint" path="..." pollingFrequency="1000"  moveToDirectory="..." connector-ref="FileConnector"&gt;
          &lt;file:filename-wildcard-filter pattern="*.csv" caseSensitive="true"/&gt;   
      &lt;/file:inbound-endpoint&gt;
  
      &lt;component class="com.package.name.CSVLineReader" doc:name="Java"/&gt;     
  
  &lt;/flow&gt;
  
  &lt;flow name="processFlow" doc:name="processFlow" processingStrategy="synchronous"&gt;
  
      &lt;vm:inbound-endpoint exchange-pattern="one-way" path="linein" doc:name="VM"/&gt;
  
      &lt;logger level="DEBUG" message="#[payload]" doc:name="Debug"/&gt;
  
      &lt;!-- Process each line of CSV file --&gt;
  
  &lt;/flow&gt;
  </code></pre>
  
  <p>My Java class is as follows:</p>
  
  <pre><code>public class CSVLineReader implements Callable {
  
      @Override
      public Object onCall(MuleEventContext eventContext) throws Exception {
  
          InputStream fileStream = (InputStream) eventContext.getMessage().getPayload();
          DataInputStream ds = new DataInputStream(fileStream);
          BufferedReader br = new BufferedReader(new InputStreamReader(ds));
  
          LocalMuleClient muleClient = eventContext.getMuleContext().getClient();
  
          String line;
          while ((line = br.readLine()) != null) {
              muleClient.dispatch("vm://linein", line, null);
          }
  
          muleClient.dispatch("vm://linein", "FILE-DONE", null);
  
          fileStream.close();     
          return null;
      }
  
  }
  </code></pre>
  
  <p>The problem I'm having is that when I'm passing each line to the VM, the order of the logs following the VM component aren't in the order that I'd expect them to be. When testing with a small (6 row) file, the order of the logs does not always match the order of the file. I'm seeing console output similar to:</p>
  
  <pre><code>DEBUG 2014-07-21 13:02:03,474 [[processes].connector.VM.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: &lt;CSV LINE 1&gt;
  DEBUG 2014-07-21 13:02:03,478 [[processes].connector.VM.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: &lt;CSV LINE 3&gt;
  DEBUG 2014-07-21 13:02:03,479 [[processes].connector.VM.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: &lt;CSV LINE 2&gt;
  DEBUG 2014-07-21 13:02:03,479 [[processes].connector.VM.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: &lt;CSV LINE 4&gt;
  DEBUG 2014-07-21 13:02:03,483 [[processes].connector.VM.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: &lt;CSV LINE 6&gt;
  DEBUG 2014-07-21 13:02:03,484 [[processes].connector.VM.mule.default.receiver.06] org.mule.api.processor.LoggerMessageProcessor: FILE-DONE
  DEBUG 2014-07-21 13:02:03,485 [[processes].connector.VM.mule.default.receiver.05] org.mule.api.processor.LoggerMessageProcessor: &lt;CSV LINE 5&gt;
  </code></pre>
  
  <p>I've had to omit the actual CSV content for confidentiality but as you can see, the order is incorrect and sometimes I'm seeing the <code>FILE-DONE</code> log before the last line of the file I'm reading.</p>
  
  <p>I'm wondering if there's a way I can force the VM endpoint to follow a synchronous, first-in-first-out, type processing strategy? I've already set the <code>processingStrategy</code> for my flows to be synchronous, but this doesn't seem to help the issue I'm having. For reference, I'm using Mule 3.4.0.</p>
  
  <p>Any help would be appreciated. Thanks in advance.</p>