Skip to content

Instantly share code, notes, and snippets.

@cmoulliard
Created May 27, 2015 07:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoulliard/0dc9a0981ad9099bb4e6 to your computer and use it in GitHub Desktop.
Save cmoulliard/0dc9a0981ad9099bb4e6 to your computer and use it in GitHub Desktop.
Apache Camel with DSL
package org.jboss.fuse.camel;
import java.util.Date;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MainApp2 {
private static Logger logger = LoggerFactory.getLogger(MainApp2.class);
private Main main;
public static void main(String[] args) throws Exception {
MainApp2 app = new MainApp2();
app.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
logger.info("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://exercise1delay1=2000").routeId("# Timer Exercise 1 #")
.setBody().constant("Hello user")
.to("direct:logResponse");
from("direct:logResponse")
.log(">> This is the first Camel exercise - ${threadName}")
.log(">> Payload received : ${body}, Headers : ${headers}")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
logger.info(">> Invoked timer at " + new Date());
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment