title: Reading from multiple dynamic locations in Apache Camel
body: <p>I have a batch job in which I'm expected to download file from multiple locations in Apache Camel.</p>
  
  <p>I'm using following strategy to complete this process.</p>
  
  <ul>
  <li>Start route on a <code>quartz2</code> schedule</li>
  <li>Retrieve list of endpoints to download files (This can be either sftp locations or simply file locations)</li>
  <li>For each file in list,</li>
  <li>Download file</li>
  <li>Save in destination.</li>
  </ul>
  
  <p>So, the problem is with downloading file. As per my knowledge, there is no way to consume file in middle of a camel route.</p>
  
  <p>There is <strong>Enrich</strong> EIP. But I can't use it as file locations are dynamic and <strong>Enrich</strong> does not support dynamic files names till version camel version 2.16. For some reasons, I'm expected to stick with version 2.15.1...redhat..</p>
  
  <p>So, to overcome this issue, I have written a custom processor for downloading the file. Following is my code for custom processor.</p>
  
  <pre><code>public class DynamicConsumer implements Processor{
  
  @Override
  public void process(Exchange inExchange) throws Exception {
      CamelContext camelContext = inExchange.getContext();
      ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate();
      String resource = inExchange.getProperty("RESOURCE", String.class);
  
      consumerTemplate.start();
      Exchange resourceExchange = consumerTemplate.receive(resource);
      consumerTemplate.stop();
  
      inExchange.getOut().setBody(resourceExchange.getIn().getBody());
      inExchange.getProperties().putAll(resourceExchange.getProperties());
      inExchange.getOut().getHeaders().putAll(resourceExchange.getIn().getHeaders());
  }
  
  }
  </code></pre>
  
  <p>This custom processor is downloading files as expected. But the problem is, it is not deleting <strong>Camel Lock</strong> after downloading the file.</p>
  
  <p>So, I would like to know</p>
  
  <ul>
  <li>Whether I'm using custom processor in the right way?</li>
  <li>Why camel is not removing the file lock after downloading/reading the file</li>
  </ul>