LibraryLink ToToggle FramesPrintFeedback

Adding RouteBuilders to the CamelContext

RouteBuilder objects represent the core of a router application, because they embody the routing rules you want to implement. In the case of a standalone deployment, you must manage the lifecycle of your RouteBuilder objects explicitly, which involves instantiating the RouteBuilder classes and adding them to the CamelContext instance.

Example 1.3 shows the outline of the standalone main() method, highlighting details of how to add a RouteBuilder object to a CamelContext instance.


Where the preceding code can be explained as follows:

1

Define a class that extends org.apache.camel.builder.RouteBuilder to define the routing rules. If required, you can define multiple RouteBuilder classes.

[Note]Note

When defining routes that include transactional components, you must extend org.apache.camel.spring.SpringRouteBuilder instead of RouteBuilder. See Transactional Client in Implementing Enterprise Integration Patterns.

2

The first route implements a hop from a JMS queue to the file system. That is, messages are read from the JMS queue, test.queue, and then written to files in the test directory. The JMS endpoint, which has a URI prefixed by test-jms, uses the JMS component registered in Example 1.2.

3

The second route reads (and deletes) the messages from the test directory and displays the messages in the console window. To display the messages, the route implements a custom processor (implemented inline).

4

Call the CamelContext.addRoutes() method to add a RouteBuilder object to the CamelContext instance.