File Processing in Apache Camel

Let me begin with this statement: “Camel is very powerful and very flexible.” Having said that, I believe I am not there yet or Camel is not there yet. Although myself and Camel are not in superb terms with each other, I started to fall in love with it. Lets look at its File Processing Capabilities.Keep looking at this post for updates.

As mentioned in my earlier post, it is very easy to create a file poller over a location. The syntax is

<camel:from uri=”file:src/data?noop=true”/>

It is this one line when put in a route will start polling the folder and will keep on executing the route for each file found in the location.

Here are a few snippets I have found useful regards to this file processing.

1. Get the name of the current file that is being processed.

${in.header.CamelFileName}

But this has to be handled in a language like simple. For example,I wanted to get control over the file name and detect if the file name contained some text, so I used,

<choice>
<when>
<simple>${in.header.CamelFileName} contains “Auto”</simple>

<!– Do something here –>

</choice>

Getting started with Apache Camel. Step by step Instructions.

To my surprise, Apache Camel is very easy to setup. I will give a try on setting it up on my eclipse but this way is even more easier.

Follow these steps:

  • There is an IDE called as Fuse IDE (which is actually built on eclipse). Go ahead and download it from here.
  • Also install maven and set it up.
  • You have installed Apache Camel. But lets test a little project on it.
  • Open the IDE and click on File > New > Fuse Project.
  • Select Use default Workspace Location. Click Next
  • Now you will have a bunch of options. Select camel-archtype-spring as shown below.
  • camel
  • Give the name of your project as Artifact ID. Click Finish.
  • You are done. This will come up with an example mentioned in my first post.
  • Go to src/main/resources > META-INF > spring and open camel-context.xml.
  • Right click on the file in the editor and click Run As> Local Camel Context.
  • Bingo, you have installed Camel, set it up and executed a project.