RouteBuilder objects represent the core of your router application,
because they embody the routing rules you want to implement. In the case of a standalone
deployment, you have to manage the lifecycle of your RouteBuilder objects
explicitly, which involves instantiating the RouteBuilder classes and
adding them to the Camel context.
Example 1.3 shows the outline of the standalone main() method, highlighting details of how to add a RouteBuilder object to the Camel context.
Example 1.3. Adding a RouteBuilder to the Camel Context
package org.apache.camel.example.jmstofile;
...
public class JmsToFileRoute extends RouteBuilder {
public void configure() {
from("test-jms:queue:test.queue").to("file://test");
// set up a listener on the file component
from("file://test").process(new Processor() {
public void process(Exchange e) {
System.out.println("Received exchange: " + e.getIn());
}
});
}
}
public final class CamelJmsToFileExample {
...
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
// Add components to the Camel context.
// ... (not shown)
// Add routes to the Camel context.
context.addRoutes(new JmsToFileRoute());
// Start the context.
context.start();
// End of main thread.
}
}Where the preceding code can be explained as follows:
Define a class that inherits from
| ||||
The first route implements a hop from a JMS queue to the file system. That is,
messages are read from the JMS queue, | ||||
The second route reads (and deletes) the messages from the | ||||
Call the |