An introduction to Apache Camel - Blog Series

Recently on twitter I noticed some tweets about Apache Camel, which covers getting started with Apache Camel.

So far there are three blogs, and there are more coming. If you want to get more familiar with what Camel is, as well how to get started with a new project, and kick the tires yourself. Then the blog series is well worth a read.

Part 1 - Introduction to Apache Camel
Part 2 - Maven project setup for a sample camel spring dsl project
Part 3 - Writing Camel Routes Using Spring DSL based XML

Happy reading. And happy new year.


Apache Camel - A little Scala DSL example

So we have a Scala DSL in Apache Camel for many years now, and I guess its about time I wrote a little blog entry about this (has been on my todo list for a while). 

So the Scala DSL is of course using the Scala programming language which has many bells and whistles over plain Java. However the uptake of the Scala DSL is not very high, as the Java and XML DSL's is good enough for most people.

Anyway I guess one of the nice thing about the Scala DSL would be using closures as expressions and predicates etc. So let's do a little example using the Filter EIP pattern and use a closure as the filter predicate.

When using the Scala DSL you should use the org.apache.camel.scala.dsl.builder.RouteBuilder, which is the Scala empowered DSL. 

So in the following we have a FilterRoute class where we use the Scala DSL, when we define the createMyFilterRoute function.

class FilterRoute {
  def createMyFilterRoute = new RouteBuilder {
      .filter(_.in("gold") == "true")

As you can see from the code above, inside the scope of RouteBuilder we have the Scala DSL at our disposal. Then we use the Filter EIP which accepts a function with the Exchange as parameter, which gets defaulted into the _ symbol. The result of that function is the evaluated as a predicate, using the Scala powerful (but a bit scary) type system with implicit type converter and case matching etc. 

The in("gold") is a function on a Exchange wrapped we have in the Scala DSL which adds additional methods on the Camel Exchange (RichExchange), the in is a function that look up a header.

To unit test this route I wanted to use the existing and powerful camel-test module. This module offers the CamelTestSupport class you can extend for your unit tests. 

So the unit tests can be almost like in Java, but you would need to add the trait org.apache.camel.scala.dsl.RouteBuilderSupport which helps bridge the Scala RouteBuilder with the Java RouteBuilder, that the CamelTestSupport expects and uses. The code below shows an unit test example.

class FilterRouteTest extends CamelTestSupport with RouteBuilderSupport {

  override def createRouteBuilder() = new FilterRoute().createMyFilterRoute

  def testFilterRouteGold() {
    template.sendBodyAndHeader("direct:start", "Hello World", "gold", "true")

  def testFilterRouteNotGold() {
    template.sendBodyAndHeader("direct:start", "Hello World", "gold", "false")


As you can see we use the RouteBuilderSupport trait, and then override the createRouteBuilder function to return the Scala DSL empowered RouteBuilder we created previously. The rest of the code is standard and plain Java code with JUnit @Test annotations.

This example is provided in the source code of the camel-scala module, as part of an unit test.

If you are a Scala fan and interested in Camel as well, then the Camel community could use people who are dedicated to Scala and help with the Scala DSL. The Camel team is often busy with other issues in our lives, so we only have a bit time to have fun and play with Scala.


Upcoming webinar - Getting started developing with Apache Camel and Fuse IDE

I am giving a webinar next week on getting started developing with Apache Camel with Fuse IDE.

Date: December 15th
Speaker: Claus Ibsen
Time: 11:00AM EST

This webinar is a hands-on practical tutorial on how to get started integrating applications with Apache Camel using Fuse IDE.

The webinar begins with a brief overview of Apache Camel, and why it makes integration tasks much easier. We then quickly get practical and develop our first integration application using Camel and Fuse IDE. Slowly we progress and show how to implement integration solutions using, but not limited to, files, ftp, jms, web servies, csv, xml, objects.

We also work with a number of Enterprise Integration Patterns such as Content Based Router, Recipient List, Splitter, Aggregator, Message Translator, Service Gateway and Idempotent Consumer. This webinar also touches on how you can gain insight into running Camel applications, to better understand what's happening, using message tracing. All together this is a very practical webinar with fewer slides and more live code and development.

Accompanying this webinar we have an eBook with sample code to ensure that after the webinar, you have material to successfully get started integrating applications with your Apache Camel journey.

You can register here.


Java Day Riga

I was invited to speak at the Java Day Riga Conference.

The conference took place at the Tallin Riga Hotel, which is a very nice hotel, just opened a couple of years ago. The hotel is also placed in the city centre, with walking distances to the nice areas.

I would like to thank Dmitry, for inviting me, and Oracle for sponsoring this event. According to Dmitry, the event would not be possible without the good faith from the Oracle. The event was free, so we had about 200+ attendees.

I like the badges, having a big and easy to read name.
Conference badget with easy to read names

The evening before the conference, we went out on a guide tour to see Riga. We hired a history professor, whom was very enthusiastic and knew a lot about what has happened to Riga over the many years. Riga is a very old city, named after the river, and it has been taken over many times between Germans, Polishes, Swedes, Russian etc.

Monument of freedom in Riga centre
The big monument in the city centre is the monument of independence, and on top it holds three stars, one for each of the three regions of Latvia.

Unfortunately after one hour it become too cold to pay attention, and we have already seen 4 churches, and many historical buildings. We found a place selling mulled wine, so we could get a bit of warm.

History Tour in Riga. Drinking mulled wine to get a bit warmth
After the tour we went for a later dinner, and just a few beers. The conference starts the next morning.

The keynote talks was good talks about the upcoming lambda expressions in Java 8. As well a talk about JEE 7, which has focus on the cloud.

Martijn Verburg preparing for his talk
Martijn Verburg, did a great talk titled "Diabolical Developer". It's a sort of pep-talk with common sense, where Martin says what some people may think is controversial. But what he really want to say, is that "think for yourself".

Martijn thinks developers are awesome
I gave a talk about Enterprise Integration Patterns and Apache Camel. In the talk I also demonstrated live coding, how to setup a new Camel project, and get that up and running in Eclipse etc. As well some of the powers of the Fuse IDE, which has graphical notation of your Camel routes, using the industry standard EIP icons. Likewise Fuse IDE is capable of doing runtime insights into running applications, which helps you pin point what is going on, as well being able to see performance statistics, with graphical representation etc.

In the end of the talk, the audience was giving a choice of either talking about Apache ServiceMix or the Camel roadmap. The audience chose the latter, so I gave a round about what to expect in the next Camel 2.9 release. Then we ran out of time. A talk for 50 minutes, is frankly a bit on the short side. 1h is usually the minimum.

In the airport on my way home. I spotted the Camel.
Camel spotting at the airport