Running Camel standalone and have it keep runningPage edited by Claus IbsenChanges (2)
Full ContentRunning Camel standalone and have it keep runningIf you are using Camel as a standalone Java application, then Camel provides a Main class you can reuse to more easily boot up Camel and keep it running until the JVM terminates, for example when pressing ctrl + c. The Main class is provided in the following two components
Using camel-core JAR exampleAvailable as of Camel 2.6 The following example shows how you can create your main class, named MainExample and use the Main class from Camel. MainExample public class MainExample { private Main main; public static void main(String[] args) throws Exception { MainExample example = new MainExample(); example.boot(); } public void boot() throws Exception { // create a Main instance main = new Main(); // enable hangup support so you can press ctrl + c to terminate the JVM main.enableHangupSupport(); // add routes main.addRouteBuilder(new MyRouteBuilder()); // run until you terminate the JVM System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n"); main.run(); } private static class MyRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from("timer:foo?delay=2000") .process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("Invoked timer at " + new Date()); } }); } } } Using camel-spring JAR exampleThis would be similar to the camel-core JAR example, however you would use the Main class from the org.apache.camel.spring package. See Also
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache Camel > Running Camel standalone and have it k... confluence
- [CONF] Apache Camel > Running Camel standalone and have... confluence
- [CONF] Apache Camel > Running Camel standalone and have... confluence