Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore some Route Builder components in Camel Spring Boot

Tags:

apache-camel

Camel Spring Boot scans the Spring context for RouteBuilders. From the documentation:

Camel auto-configuration collects all the RouteBuilder instances from the Spring context and automatically injects them into the provided CamelContext. That means that creating new Camel route with the Spring Boot starter is as simple as adding the @Component annotated class to your classpath

Is there a way to control this: include/exclude packages or classes.

I want to annotate certain RouteBuilders and have Camel exclude those. My intent is to add them to the CamelContext dynamically, later.

like image 265
Darius X. Avatar asked Apr 21 '17 20:04

Darius X.


People also ask

How do you stop a Camel route?

The best practice for stopping a route from a route, is to either: signal to another thread to stop the route. spin off a new thread to stop the route.

What is RouteBuilder in Camel?

The RouteBuilder is a base class which is derived from to create routing rules using the DSL. Instances of RouteBuilder are then added to the CamelContext .

How do you manually start a Camel route?

The autoStartup option on the <camelContext> is only used once, so you can manually start Camel later by invoking its start method in Java as shown below. For example when using Spring, you can get hold of the CamelContext via the Spring ApplicationContext : ApplicationContext ac = ... CamelContext camel = ac.


1 Answers

You can use these properties, that are set to the SpringBootTest Annotation.

  • java-routes-inlcude-pattern - Pattern to include routes in your test
  • java-routes-exclude-pattern - Pattern to exclude routes in your test

These are ant style properties that search through your src folder for matching RouteBuilders

Example with pattern:

// Fix test runner
@RunWith(CamelSpringBootRunner.class)
// Your spring boot application with the main method
@SpringBootTest(classes = {SpringBootTestRunner.class},  
    // Finds all routes in your whole src folder that start with 'SomeRoute', e.g. SomeRouteOne
    properties = {"camel.springboot.java-routes-include-pattern=**/SomeRoute*"})
public class SomeRouteOneTestCase {
    ...   // Unit Tests
}

Example for fix class:

// Fix test runner
@RunWith(CamelSpringBootRunner.class)
// Your spring boot application with the main method
@SpringBootTest(classes = {SpringBootTestRunner.class},
    // Find the RouteBuilder 'SomeRouteTwo' in the package 'com.foo.bar' and nothing more
    properties = {"camel.springboot.java-routes-include-pattern=com/foo/bar/TestRouteTwo"})
public class TestRouteTwoTestCase {
    ...   // Tests
}

java-routes-exclude-pattern works in the same way, just exluding the listed route builders.

Hope this helps.

Greets
Chris

like image 139
Chris Avatar answered Oct 11 '22 21:10

Chris