title: Apache Camel how to add/remove endpoints dynamically from a route
body: <p>I am trying to get familiar with EIP and Apache Camel and I have a use case that I am not quite sure how can be expressed or implemented using Camel</p>
  
  <p><strong>Use case:</strong></p>
  
  <p>Imagine you have designed an integration solution that takes files from an ftp, does some processing and uploads it to a queue. You chose Apache Camel to implement this solution and your route in Java DSL looks something like this:</p>
  
  <pre><code> from("ftp://user@hostname/directoryname")
     .process(new Processor() {
                public void process(Exchange exchange) throws Exception
                {
                  //my fantastic prosessing goes here
                }
   }).to("jms:queue:queueName");
  </code></pre>
  
  <p>the route could be way more complex than this, but it doesn't matter here. Imagine your solution is such a spectacular success that there's a plan to implement a service where anyone could add his ftp server and get the files processed and uploaded to the queue. So what you want is</p>
  
  <ol>
  <li>(Flexibility) Being able to dynamically add/remove servers from your app</li>
  <li>(Scaling) Being able to handle potentially large number of such servers</li>
  </ol>
  
  <p>Let's forget about #2 and focus on Flexibility part.</p>
  
  <p>So the question is, I suppose:</p>
  
  <p><strong>How to dynamically (at runtime) add/remove endpoints to/from Apache Camel route?</strong></p>
  
  <p><strong>What I considered so far:</strong></p>
  
  <p>First, I admit I am not that familiar with Integration Patterns, but just scanning the catalogue, the only thing that kind of could fit the bill is the <em>Content Enricher</em>. It can take a message and just go off to somewhere else and bring sth else. So I was thinking if someone adds an ftp server, the connection details could be encapsulated in the message and a <em>Content Enricher</em> could then connect to that ftp server and fetch files and push it further through the route.... so it would effectively be a <em>Content Enricher</em> capable of  connecting to multiple ftp servers.... That kind of sound wrong. First I don't think this is the intention behind that pattern and secondly since there's ftp <em>Component</em> in Camel, I should somehow be able to use it in that scenario</p>
  
  <p>The second approach would be to break the route into two like using the <em>vm</em> component, like this:</p>
  
  <pre><code> from("ftp://user@hostname/directoryname").to("vm:internalQ");
   from("vm:internalQ")
     .process(new Processor() {
                public void process(Exchange exchange) throws Exception
                {
                  //my fantastic prosessing goes here
                }
   }).to("jms:queue:queueName");
  </code></pre>
  
  <p>so now, I can create many routes with ftp endpoints that write to that internal queue so it can be picked up. Adding route dynamically to <em>CamelContext</em> seems to be possible (<a href="https://stackoverflow.com/questions/10451444/add-camel-route-at-runtime-in-java">Add camel route at runtime in Java</a>). Is that the way to go? Or am I just trying to use <em>Camel</em> in a way that it was not designed to?</p>