Tuesday, March 30, 2010

Run Camel route on ServiceMix 3.3.x

Even if Apache ServiceMix (ESB) was mainly designed as a JBI container, it is perfectly possible to use camel routes and camel components (bindy, file, jms, ...) on this platform.

This allows by example to :
- Combine JBI binding components or Services with Camel routes,
- Use a camel component when the binding component does not exist,
- Deploy camel as Service Unit in Service Assembly

Here is a small example showing that in action. The creation of the project is very simple as you have to create a Service Unit. If you work with maven, you can use the servicemix plugin which will allow to create the maven project. Otherwise, you can create the maven structure manually.

To be able to deploy camel next, you must create a Service Assembly (= SA) who will include the Service Unit.

Don't be afraid and follow the tutorial described here for that part of the work : http://servicemix.apache.org/2-beginner-using-maven-to-develop-jbi-applications.html

When the project is ready, you create a camel-context.xml file in the directory src/main/resources. This file which is a spring xml file will contain the camel routes + beans definitions or will point to your packages if you prefer to code your routes using Camel Java DSL language instead of Spring DSL language.

Remark : in my example, I use Spring DSL language.

The route is very basic and will create a message containing the text "Hello World from SMX3!" as body value. The message is copied in an activemq queue called "in". A second route take the messages and send it to the log. The log message is readable from the console where ServiceMix 3.3.x has been started.

In the Spring file, you must add the camel bean "org.apache.camel.component.jms.JmsComponent" definition to instantiate a connection factory to the queueing engine. The broker is created and started at the launch of ServiceMix3 so you don't need to do anything else here !


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">










org.apache.servicemix.samples




Hello World from SMX3 !













To allow Camel to work with its jms component, the following dependency must be added in the pom of the camel-su.





org.apache.camel
camel-core
2.2.0


org.apache.camel
camel-spring
2.2.0


org.apache.camel
camel-jms
2.2.0






To compile the project, simply launch the command "mvn install" to generate the SU and do the same for the SA. When the Service Assembly jar file is available, copy it in the hotdeploy directory of ServiceMix 3 server and check the log.

This example which is very basic can be extended with another camel components. In that case, don't forget to add their dependency in the SU pom as the camel lib must be added in the lib directory of the SU.

Have fun with that !

7 comments:

Architecture-Seenu said...

Hi great post, I looked at servicemix 3 and 4. I settled on Fuse Esb mainly because of osgi (sm4). I have a question not related to the post, if you don't mind. What do you use to format code, I have been looking for something like that for my blog. Thanks in advance.

cmoulliard said...

I use simply a javascript syntax highlighter --> http://code.google.com/p/syntaxhighlighter/

Architecture-Seenu said...

Thanks, appreciate it.

R110926oseH said...

thank you for you to make me learn more,thank you∩0∩ ........................................

Jean-Marc said...

Hi Charles,

I'm using smx 4 and Camel 2.2 and I would like to deploy the Camel Web console on karaf 1.2

I have the same problems like you :
http://www.mail-archive.com/users@camel.apache.org/msg05416.html

Do you have found a solution for this last issue ?

Thanks in advance

JMH

cmoulliard said...

Hi Jean-Marc,

As mentioned in the post (see your link), the solution to this problem is to expose the javax.xml packages by removing the comment in front of the lines in the system.properties file of SMX4.

Remark : My post was focused on SMX3 !!

Kind regards,

Charles

Android app development said...

This is one of the good Article.This is one of the great post.I like your blog features.
Android app developers