In the case of a standalone deployment, the application developer to creates,
configures and starts a CamelContext instance (which encapsulates the core of the router
functionality). For this purpose, you should define a main()
method that
performs the following key tasks:
Create a CamelContext
instance.
Add components to the CamelContext
instance.
Add RouteBuilder
objects to the CamelContext
instance.
Start the CamelContext
instance, so that it activates the routing rules you defined.
Example 1.1 shows the standard outline of a standalone main()
method, which is defined in
an example class, CamelJmsToFileExample
. This example shows how to initialize and activate a
CamelContext
instance.
Example 1.1. Standalone Main Method
package org.apache.camel.example.jmstofile; import javax.jms.ConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.camel.CamelContext; import org.apache.camel.CamelTemplate; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.jms.JmsComponent; import org.apache.camel.impl.DefaultCamelContext; public final class CamelJmsToFileExample { private 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.
// ... (not shown) // Start the context. context.start();
// End of main thread. } }
The code in Example 1.1 does the following:
Define a static | |
Instantiates a | |
Adds any components that are required to the | |
Adds the | |
The |