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.
Example 1.3. Adding a RouteBuilder to the CamelContext
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 CamelContext. // ... (not shown) // Add routes to the CamelContext. 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 extends
| ||||
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 |