title: Separate route instances within single Camel context
body: <p>I use Apache Camel module deployed inside ActiveMQ service.</p>
  
  <p>Given I use Spring DSL and I have route definition ( implemented as <code>routeContext</code>) in the <code>FilteringRouteContext.xml</code> file (simplified):</p>
  
  <pre><code>&lt;routeContext id="filteringRouteContext" xmlns="http://camel.apache.org/schema/spring"&gt;
      &lt;route id="myFilteringRoute"&gt;
          &lt;from uri="direct:filteringRoute"/&gt;
          &lt;idempotentConsumer messageIdRepositoryRef="idempotentRepository" skipDuplicate="false"&gt;
              &lt;simple&gt;${header.JMSType}&lt;/simple&gt;
              &lt;filter&gt;
                  &lt;property&gt;CamelDuplicateMessage&lt;/property&gt;
                  &lt;stop/&gt;
              &lt;/filter&gt;
          &lt;/idempotentConsumer&gt;
      &lt;/route&gt;
  &lt;/routeContext&gt;
  </code></pre>
  
  <p>Next, I have configured Camel Context in other XML file (simplified):</p>
  
  <pre><code>&lt;import resource="classpath:FilteringRouteContext.xml"/&gt;
  
      &lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
  
          &lt;routeContextRef ref="filteringRouteContext"/&gt;
  
          &lt;route id="myRoute1"&gt;
              &lt;from uri="activemq:topic:source1" /&gt;
              &lt;to uri="direct:filteringRoute" /&gt;
              &lt;to uri="activemq:topic:target1" /&gt;
          &lt;/route&gt;
  
          &lt;route id="myRoute2"&gt;
              &lt;from uri="activemq:topic:source2" /&gt;
              &lt;to uri="direct:filteringRoute" /&gt;
              &lt;to uri="activemq:topic:target2" /&gt;
          &lt;/route&gt;
  
          &lt;route id="myRoute3"&gt;
              &lt;from uri="activemq:topic:source3" /&gt;
              &lt;to uri="direct:filteringRoute" /&gt;
              &lt;to uri="activemq:topic:target3" /&gt;
          &lt;/route&gt;
  
      &lt;/camelContext&gt;
  
      &lt;bean id="idempotentRepository"
            class="org.apache.camel.processor.idempotent.MemoryIdempotentRepository"&gt;
          &lt;property name="cacheSize" value="10"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I would like to have shared route (with id=<code>myFilteringRoute</code>) from <code>filteringRouteContext</code> declared as, using IoC terminology, <strong>instance per dependency</strong>, so each route from single Camel Context (with id=<code>myRoute1</code>, <code>myRoute2</code>, <code>myRoute3</code>) should use it's own instance of that shared route (with id=<code>myFilteringRoute</code>), with separate internal state, bean instances, etc.</p>
  
  <p>In other words, each route from Camel Context (with id=<code>myRoute1</code>, <code>myRoute2</code>, <code>myRoute3</code>) <strong>should not use the same instance of shared route</strong> (with id=<code>myFilteringRoute</code>), but should has its <strong>own completely separate instances</strong> (with completely separated internal states and bean instances )</p>
  
  <p>Please consider that my shared route (with id=<code>myFilteringRoute</code>) may use more beans, which may have various scopes (<code>singleton</code>, <code>prototype</code>, <code>request</code> etc.).</p>
  
  <p>My questions are: Can I achieve this goal using single Camel Context, or do I need to place my routes (with id=<code>myRoute1</code>, <code>myRoute2</code>, <code>myRoute3</code>) in separate Camel Contexts? What is the best solution of my problem?</p>
  
  <p>Is there important performance impact If I use more than one Camel Contexts, and each context uses beans to communicate with ActiveMQ (<code>org.apache.activemq.camel.component.ActiveMQComponent</code>), or other beans that consume internal or system resources?</p>
  
  <p>Or maybe it's better to resolve my problem by using Java DSL instead of Spring DSL?</p>
  
  <p>Thank You.</p>