Apache Camel is one great implementation of the EIP pattern, If you are not a seasoned Spring/Java developer , you might found it’s hard to get started, the goal of this post is simplify that process and show you how easy to get started without remember any code snippet. we will use plain console app to host and start one camel route.
to get started, simply open eclipse and create one maven project (the purpose of maven here is to add those dependency automatically), if you don’t have any maven experience, you can simply download the required jar and add to you build path.
Create one Maven project , using the simple project type, we get one project with maven ready,
Now , right click pom.xml, click maven menu, add a dependency to camel-core, you can simply search camel-core
we’ve initialized the camelcontext, next step is adding our routes by xml or java code.
let’s start from java code first, since it has intelligence and life is little bit easier,
it looks like we can just add one RoutesBuilder to the context, is there any existing one, or we have to build our own.
ask the eclipse create a local variable for the routesbuilder, let’s see whether there is any existing one,
then the code looks like this,
in the configure , we just inject the code snippets listed on the camel component page, here is one demo, that dump out some message every 2 seconds,
if we run this, we can see the message get shown in the console every 2 seconds.
for the log component, we can’t see the message because it is NOP for slf4j by default, so lets add a slf4j-simple to the pom.xml
Change the pom.xml a little big , pint to the mainclass , you can copy the xml here
then go to the project folder, run mvn compile assemlby : Single
Now, we can run the jar directly, by typing java –jar pathtothejar
for the source code, check it out here, https://github.com/ryandh/apacheCamelTutorial/tree/DemoConsole