Luke
Luke

Reputation: 283

Split Camel Context definition into multiple files/jars

I need to split the camel context definition into multiple files/projects. I'd like to have one file with only global configurations (like dataFormats, onCompletion handler, onException handler, interceptFrom, operational routes) and one file which builds on top of it defining mainly routes.

I have not found any way to adjust/extend a CamelContext definition done in another file. Is there a way?

It would look like this:

camel-core.xml:

<camelContext id="camelContext">
    <interceptFrom>
        <log message="{$routeId} started" />
    </interceptFrom>
</camelContext>

camel-routes.xml:

<camelContext id="camelContext">
    <route id="camelRoute1">
        <from uri="vm:foo" />
        <log message="camelRoute1 completed" />
    </route>
</camelContext>

Desired output when running camelRoute1:

camelRoute1 started
camelRoute1 completed

Upvotes: 1

Views: 1760

Answers (2)

Luke
Luke

Reputation: 283

I've found a workaround with the Java DSL for my case:

  1. In the camelContext definition i set autoStart="false"
  2. In my project where the global camel definitions should be, I added a spring bean which implements both ApplicationListener and CamelContextAware
  3. In this bean I get all the route definitions from the camel context - including the ones defined in another project/context file. So I loop through all route definitions and add interceptFrom, onException etc. with the Camel adviceWith feature.
  4. I then start all routes with context.startAllRoutes().

works :-)

Upvotes: 2

Dinesh Arora
Dinesh Arora

Reputation: 2255

It's possible to do this. Use <import resource="myCoolRoutes.xml"/>

See documentation - http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html

Upvotes: -1

Related Questions