Created
May 27, 2015 07:40
-
-
Save cmoulliard/0dc9a0981ad9099bb4e6 to your computer and use it in GitHub Desktop.
Apache Camel with DSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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