Hi All,

I like to use the routesLoader (
https://javadoc.io/static/org.apache.camel/camel-api/3.16.0/org/apache/camel/spi/annotations/RoutesLoader.html
).
I have some questions about how to properly use it.

1) Is there any documentation on how to use it? (At
https://camel.apache.org/manual/ or
https://camel.apache.org/components/next/index.html).

2) I could find some examples (https://github.com/apache/camel-examples),
there the routesloader example says:

<!--
    if you want to have multiple routes, you can either have multiple files
with 1 <route> per file or
    you can use <routes> as root tag, such as
<routes><route>...</route><route>...</route></routes>
-->

<route>
    <from uri="timer:xml?period=5s"/>
    <log message="I am XML"/>
</route>

These examples loads xml, can it also loads other DSL's? (Like yaml or
Java).

3) How to use OnException with the RouteLoader?

I thought maybe like this

<routes xmlns="http://camel.apache.org/schema/spring";>
<onException>
 <exception>java.lang.Exception</exception>
 <redeliveryPolicy maximumRedeliveries="0" redeliveryDelay="5000"/>
 <handled><constant>true</constant></handled>
 <toD uri="file://some/directory"/>
</onException>
<route>
<from uri="timer:xml?period=5s"/>
<log message="I am XML"/>
</route>
</routes>

But this gave me a nullpointer exception.

4) Load from string directly

In Camel 2 you could load routes directly from string like this:

ManagedCamelContext managed =
context.getExtension(ManagedCamelContext.class);
managedContext = managed.getManagedCamelContext();
managedContext.addOrUpdateRoutesFromXml(routeAsString);

In Camel 3 the "addOrUpdateRoutesFromXml" is depracated. With routeLoader
from string I do it like this:

ExtendedCamelContext extendedCamelContext =
context.adapt(ExtendedCamelContext.class);
RoutesLoader loader = extendedCamelContext.getRoutesLoader();
Resource resource = ResourceHelper.fromString("any.xml", route);

loader.updateRoutes(resource);

Is this the only way in Camel 3, or is there also a specific method to use
strings directly (and maybe only specify the DSL used) like:

loader.updateRoutes(routeAsString, "xml");


Raymond

Reply via email to