Search code examples
spring-bootapache-camel

Startup a Camel Spring DSL route


I am somewhat of a novice working with the Camel Spring DSL Routes. My experience has been mostly with Java DSL.

I recently looked at a project that was based on Camel Spring DSL and noticed that the entire project consisted of just the XML Routes and a few supporting classes for special Processors. Nowhere could I found a Java class to actually Start the route(s) running. I was expecting to find a class that started with something like:

@SpringBootApplication
public class LocalAppRunner {

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(LocalAppRunner.class);
        springApplication.setBanner(new TraneBanner());
        springApplication.setAdditionalProfiles("local");
        springApplication.setBannerMode(Banner.Mode.LOG);
        springApplication.run(args);
    }

But evidently there is is no need for any class ( that is overtly written as part of the project ) to fire up the Route.

My guess is that the Route is started with something like mvn spring-boot:run

Can anyone clarify if I am am correct in this assumption that Spring DSL does not require an overt Java ( or Groovy ) class to fire up a route but can rely on just a mvn reference as indicated above. ( of course the POM file would need the proper entries )


Solution

  • It's likely that the project in question is camel-spring project and not a camel-spring-boot project. Based on the camel-archetype-spring the startup method is hidden in the org.apache.camel.spring.Main class of camel-spring-main dependency.

    By default camel-spring-main looks for spring xml configuration files from the META-INF/spring/ folder. The application can be started with the camel-maven-plugin using mvn camel:run command.

    If you however want to run camel routes defined with xml with camel-spring-boot project you can place the xml files to path src/main/resources/camel/ in your project. For more information you can look at the documentation.

    Example file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- routes.xml -->
    <routes xmlns="http://camel.apache.org/schema/spring">
        <route id="test">
            <from uri="timer://trigger?period=1000" />
            <log message="Hello from xml" />
        </route>
    </routes>
    

    The file should only contain the route definition as camel-spring-boot-starter handles creating and configuring CamelContext.