Monday, February 28, 2011

Beginners guide to Apache Camel with ServiceMix: Part2

This is part 2 of the Beginners guide to Apache Camel with ServiceMix. The first part explained how to set up the environment, to run the examples developed in this post. You can find part 1 here. In this section we will create a Maven project with the camel-spring archetype, change the route with Fuse IDE for Camel, test the route in Eclipse and deploy the route to ServiceMix.

Developing, testing and deploying a simple route
Create Maven project in Eclipse
  • In Eclipse go to File - New - Project...
  • Choose Maven - Maven Project
  • Choose Use default Workspace location and Next
  • Select an archetype
    • Catalog: Fuse Catalog
    • Filter: camel
    • Choose: camel-archetype-spring
    • Next
Click to enlarge 
  • Set archetype parameters:
    • GroupId: tutorial
    • ArtifactId: simple_router
    • Version: 1.0.0
    • Package: tutorial.simple_router
    • Finish
Click to enlarge
  • This creates a new Maven project with the following structure. It would be advised to change the name of the camel xml file to something more descriptive (simple-router in this case), as this is the file that will be deployed.
  • If we double click this file we can get a graphical overview of the routing together with the properties of each node. You can change the mapping by deleting nodes, dragging in new nodes and changing the properties of each node.
Click to enlarge

Click to enlarge
Testing the route in Eclipse
  • To test the route click on the root of the project - Run As - Run Configurations.
Click to enlarge
  • Run Configuration:
    • Base directory: Set the base directory to your project root "C:\Documents and Settings\Administrator\workspace\simple_router"
    • Goals: camel:run
    • Run
Click to enlarge
  • If everything succeeds you should see something like this: "Apache Camel 2.6.0 (CamelContext: camel-1) started in 1.421 seconds"
Deploying the route to ServiceMix
Deploying the route to ServiceMix is as simple as copying the camel xml file (spring file) to the deploy directory in ServiceMix. 
  • Fire up ServiceMix
    • In cmd change directory to the ServiceMix\bin directory. 
    • Execute servicemix.bat
Click to enlarge
  • Copy the "simple-router.xml" file 
    • found in this directory C:\Documents and Settings\Administrator\workspace\simple_router\src\main\resources\META-INF\spring
    • the deployment directory directory C:\Program Files\Apache Software Foundation\apache-servicemix-4.3.0-fuse-02-00\deploy
  • To see if the route has been successfully deployed you can use the Apache Felix Web Console. 
    • To install the console run the following command in karaf prompt:
      features:install webconsole
    • You can access the Web Console from the following address:
    • Use "smx" as default username and "sxm" as default password.
Click to enlarge
Testing the route
  • To see if the route works, drop a file in the ServiceMix\src\data directory.
Click to enlarge
  • Moments later the file should land on the ServiceMix\target\messages target directory (either "uk" or "other" depending on the file content)
Click to enlarge


  1. it's works, thanks for the nice tutoriel, but i don't understand very well the use case. finally i'm new in fuse esb, can you give me some advice for a simple helloworld example.

  2. Hi Safi, I'm glad the tutorial worked for you. I had no specific use case in mind for this. My main aim was to get a simple Fuse IDE for Camel example working and deployed to Fuse ESB (ServiceMix). The tutorial shows you how to start a simple Camel development. Once your environment has been set up and the maven project created and deployed, you can modify it to meet any requirement. I think this is the power of FuseIDE for Camel. In the past it wasn't so easy to change a scenario without breaking something.

    Regarding your request for a Fuse ESB example; the above tutorial already deployed a simple Camel route to the Fuse ESB (ServiceMix). Remember, Fuse ESB consists of the different Fuse components like Fuse Mediation Router (Camel), Fuse Message Broker (ActiveMQ) etc. In this tutorial, I deployed the Camel route by simply copying the Camel XML file to the deploy directory of the Fuse ESB. Once this is done, we only need to fire up the Fuse ESB and not all the individual Fuse components.

    I'm hoping to throw ActiveMQ into the mix with my next post. It will explain how to deploy an ActiveMQ\Camel example to ServiceMix.


  3. Hi Shaun,
    Thanks for response, and i'm waiting for you're next post and hope it help me.

  4. I tried this exercise, I got the following error:
    (Any Ideas)

    Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.ning.http.client.AsyncHttpClient.(
    at org.sonatype.aether.connector.async.AsyncRepositoryConnector.(
    at org.sonatype.aether.connector.async.AsyncRepositoryConnectorFactory.newInstance(
    at org.sonatype.aether.impl.internal.DefaultRemoteRepositoryManager.getRepositoryConnector(
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(
    at org.sonatype.aether.impl.internal.DefaultRepositorySystem.readArtifactDescriptor(
    at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor(
    at org.apache.maven.plugin.DefaultBuildPluginManager.loadPlugin(
    at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolveFromProject(
    at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolveFromProject(
    at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolve(
    at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.findPluginForPrefix(
    at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor(
    at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(
    at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(
    at org.apache.maven.DefaultMaven.doExecute(
    at org.apache.maven.DefaultMaven.execute(
    at org.apache.maven.cli.MavenCli.execute(
    at org.apache.maven.cli.MavenCli.doMain(
    at org.apache.maven.cli.MavenCli.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(
    Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
    ... 34 more

  5. I suspect there was already an installation of m2eclipse installed. Make sure you uninstall it before installing FUSE IDE. You can find these steps in part 1:

  6. hey i am having the same problem as 'Human Computer Class' is having and i am sure there is not previous m2eclipse installed. i installed the one provided with the link i.e.

    I am almost lost with the problem here. Any help will be greatly appreciated.

    ps. i have a doubt if it has got something to do with slf4j or log4j version. but i am not sure what it is

    maven: 3.0.2
    jdk: 1.6.0_23

  7. Nice Post.
    In fact, I also ran into the same issue of java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory. Fuse Camel IDE uses maven 3.0.2.xxxx embededded version. I created a maven installation for 3.0.3 and used that to run the sample camel:run. It worked fine.

  8. Thanks Sriraman that worked. I downloaded Maven 3.0.3. Went to Window->Preferences->Maven->Installations, clicked the Add button.
    Selected the Maven 3.0.3 install directory. I also changed the Maven Runtime pointed to by my project run configuration to point to Maven 3.0.3. Auni hopefully this helps.

  9. FYI
    I got the following error when deploying the file to ServiceMix (apache-servicemix-4.3.1-fuse-01-09):
    karaf@root> Exception in thread "SpringOsgiExtenderThread-1" java.lang.IllegalStateException: BeanFa
    ctory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationC

    However I searched around and found:

    In this context the message: "BeanFactory not initialized or already closed" is caused because there is an application context that was waiting for dependencies that were never resolved before shutdown. These messages are hard to grok, but any time you see the following line 2 lines down in the stack trace this is the reason.

    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(

    So this error message is a symptom of another issue where a spring application context can't start because of missing osgi dependencies.

    Spring has updated this for Spring DM 2.0 so that it doesn't attempt to do this if the context is still pending resolution. I am hoping they backport and release a 1.2.1, but not holding my breath. In the mean time, when you see these messages they themselves can be ignored, but search up through the log for a BeanDefinitionStoreException and that will point you to the bundle and Spring context that failed.

    So I used the Apache Felix Web Console on the
    Bundles tab to resolve all unresolved the bundles.

    Works now, however it would be nice to know which bundle(s) caused the problem. Anybody know of any debug mechanisms that would aid me in doing so?

  10. Hi!
    i'm also waiting for another good tutoriel from you. the first one is very interessting and i would show for my student! thanks

  11. Hi Safi,

    I've been wanting to do one, but I'm a bit caught up with things at work. Do you have anything specific in mind?


  12. Hi Shaun and thanks for answer!
    I would like to know it's possible for apache camel / servicemix to read data from database?

  13. Hi Shaun, Thanks a lot for the nice tutorial its working. I need to understand clearly how messages are routing back end. Could you please elaborate camel with service mix.
    Thanks in advance….

  14. Hi Shaik. I'm glad you like the tutorial. The detailed way in which Camel routes the message is abstract to the developer and is not important in simple scenarios like this one. What is important however is the outcome of the route. You can check what the outcome of the route is supposed to be by either looking at the graphical overview (as displayed in the tutorial), or you can view the generated XML source code by choosing the "Source" tab instead of the "Design" tab at the bottom left of your screen.

  15. Hi Shaun,

    Your post is very nice. I am new to ESB and need to use Apache Servicemix for this. Need help on Apache ServiceMix with sample example.

  16. Hi Shaun,

    Your post is excellent. It worked like a magic in the first attempt it self. This is great. As of now i am not sure what and how it worked, but it worked and now i will dig into it more to understand in detail.

    Please post more detail examples which would help everyone in understanding it.


  17. Hi Shaun,

    A very good post on the ServiceMix (Fuse ESB) configuration.
    I am new to this framework (ServiceMix) and trying only the Apache ServiceMix.

    Not able to find a step-by-step approach for configuring Email connectivity with any Mail Server.
    Any help in this regard will be appreciated.



  18. The default username/password combination for web console when one uses JBoss Fuse ESB now would be karaf/karaf . Also didn't relies until i look at the route that the inout file needed is an xml file.

  19. Hi ,
    Your article is very nice.
    I am very new to servicemix. now in my project we are using apache servicemix4.4.1-fuse-03-06, cxf, camel , spring and webserivces .

    Can give a post on how to work by using above things ?
    and also I downloaded servicemix 4.4.1 from apache sit, but instance folder is not coming .
    so while sarting up the servicemix get error like can not find the folder instance.
    how can I download this ?
    is there any differences between servicemix 4.4.1 and servicemix4.4.1-fuse-03-06?

    Kindly help me out


  20. Good article, I've seen many articles today, but only this article is of interest to me, thanks judi poker online yang aman dan terpercaya

  21. Great Article shaun, I am new to servicemix and camel. In article while setting up the IDE the link to the fuse IDE is not working as Fuse is now with JBoss. can we develop the same code in Jboss and deploy on service mix? Is there any additional steps for this.