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.
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.
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 .
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.
You can use these properties, that are set to the SpringBootTest Annotation.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With