vrijdag 12 oktober 2007

Using Apache Camel with ServiceMix

In the last days I have been looking at Apache Camel (http://activemq.apache.org/camel). Within ServiceMix there is a Enterprise Integration Patterns (EIP) JBI component that is very useful to implement patterns like for example content-based router, message filter, recipient list and content enricher patterns. These are of course a number of the patterns that are listed in the famous Enterprise Integration Patterns book by Hohpe and Woolf (http://www.enterpriseintegrationpatterns.com/). But this servicemix-eip module is limited in the support for these patterns and on the ServiceMix site, Apache Camel is referenced as an important alternative. In August Apache Camel 1.1 was released and with this release there is quite a lot of attention about this framework. ServiceMix also has a JBI component so that Camel can easily be integrated within ServiceMix. So I thought it would be a good time to develop some hello world type of implementation of ServiceMix with Camel.

The hello world type example that I implemented is a file poller that sends the file contents via Camel to a file sender. So the example just picks up a file from the inbox directory and sent it to the outbox directory. For people who know the ServiceMix service assembly configuration this maybe a bit simple, but the layout of the service assembly that I've implemented looks like this:


The hello assembly (hello-sa) is eventually deployed to the ServiceMix container. But what is important is the xbean.xml configuration for the file and the camel service units. Let's start with the file service unit xbean.xml.

<beans xmlns:sm="http://servicemix.apache.org/config/1.0"

<file:poller service="esb:poller" endpoint="endpoint"
targetService="esb:camelReceiver" targetEndpoint="endpoint" file="file:inbox" />

<file:sender service="esb:sender" endpoint="endpoint" directory="file:outbox"/>


So we have a simple file poller on the inbox directory and a file sender to the outbox directory. The target service for the incoming file contents, configured with the file poller, is the camelReceiver. This service is configured in the xbean configuration of the camel service unit.

<beans xmlns="http://www.springframework.org/schema/beans"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd

<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
<from uri="jbi:service:http://esbinaction.com/helloworld/camelReceiver"/>
<to uri="jbi:service:http://esbinaction.com/helloworld/sender"/>


So this is a very simple Camel XML configuration that just forwards the file contents from the camelReceiver service to the sender service. This same kind of Camel routing could also have been implemented in Java and then it looks like this.

RouteBuilder routeBuilder = new RouteBuilder {

   public void configure() {




<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">

So this a very simple example on how to use Camel within ServiceMix.

1 opmerking:

Joe zei

I tried to implement your example but got the following using iona fuse

Unable to find suitable deployer for Service Unit 'hello-camel-su'

probably doesn't have anything to do with your example, but any help you could give would be appreciated.