On the road to Camel 2.0 - OnCompletion

Its time to write a new blog entry on another new feature in Apache Camel 2.0 - on completion.

On completion allows you to do additional routing when an exchange has been completed.

Imagine you need to register a special log entry when a particular route is complete. What you could do at first sight was just to add a processor at the end of the route that would log the entry.

But now the processor is part of the original route and it could potential affect the outcome. For instance lets say the processor could not log the entry and fails, or it accidently changed or altered the payload, or it was time consuming. All affecting the original route.

So how can we avoid this? What we want to do is to execute our processor after the original route is complete. With the new onCompletion DSL you can do this.

Lets look at a little sample to help understand how its setup and works.

First we define a route as below:

And then we want to do run our custom processor FileCompletionProcessor when the route is complete. So what we do is to register an onCompletion on this route.

This is done by adding our onCompletion
.process(new FileCompletionProcessor())

... to the route as shown below:

.process(new FileCompletionProcessor())

Notice: We need to declare an end() on the onCompletion route to indicate the end of this one. What it means is that the onCompletion is a first class route on its own. So you can do all the DSL in this route as you like. You can do content based routing, filtering, invoking additional processors or beans etc. For Camel its just another route.

What happens is that when the original route is complete, e.g. the file content have been send to the activemq queue and the route is complete. Then the onCompletion kicks in. What Camel does internally is that it starts a new route in another thread that has a copy of the original exchange, that is routed in the onCompletion route. So the original route continues to run in its own thread to complete immediately. This ensures that the onCompletion route will not affect the original route.

The sample above was a basic example. What if you only want to do special work in case the original route failed? Well Camel supports DSL to specify:
- onFailureOnly
- onCompleOnly

For instance we want to invoke a bean registered with the id failureService in case the route failed. We can do this as:
.beanRef("failureService", "fileFailed")

And just like other functions in Camel onCompletion also supports scopes:
- global
- route

And the onWhen predicate that you might have seen as well.

Take a look at the documentation for further details and sample. It provides XML samples as well.


Apache Camel 2.0m2 released

Yeah finally we got the 2nd and last milestone for Apache Camel 2 released.

And this time even the front page at Apache Camel has the news item in time :)

I had used 30 minutes to write a nice summary of the important new features in this release. But somehow Blogger managed to shrew things up so it got lost. Damn why does it not auto save and let you look back revisions of edits. What I could get back was just the first 2 lines. So I am not in the mood to rewrite it again, so I keep this blog post short.

You can check out from the release notes here.

This is the last planned milestone release. The plan is to use close in on the final release, fixing bugs and adding a few new features. And maybe taper a little with the API as we can seize the moment and do it before 2.0 is out. We hope to get 2.0 out within 1 month.

Please give 2.0m2 a test drive and we are especially interested in hearing about your experience if you upgrade from existing Camel 1.x applications.


Need tooling for Camel? We got FUSE tooling

At FUSE we do have tooling for Apache Camel. In fact the new FUSE Integration Designer 1.2 release is out of the door.

This tool have visual route editing for Apache Camel. My fellow colleague Oisin Hurley, whom is the leader on FUSE tooling announced it on his blog.

What is especially interesting for Camel in this release is that they have added all the EIP patterns we have in Camel. And its really cool to finally be able to see the routes in great looking diagrams. Its like being able to see the Matrix code as motion picture instead of green scrolling text.

Its a two way editor so you can import existing Camel routes, continue to edit them and export it back. And yes you can also export the diagrams as image files so you can put them in word documents or the likes.

You can read more about the FUSE Integration Designer and downloads at this link.

And head over to the FUSE Tooling forum where you can ask questions about the tooling and even meet Oisin himself on the forum.