Simple JBOSS Fuse/Karaf Camel route deployment

To get started with Camel for routing, you can simply drop a file in the deploy directory under your Fuse installation. However, in a production environment, it is advisable to have more controlled process for deploying routes. That is the purpose of this post. As always, the goal is to produce a simple test case with as few steps as possible, yet provide a system connection example so you can read the documentation from a more “kinetic” learning standpoint.

Start with a maven project.

[esb@cmhlcarchapp01 poc]$ mvn archetype:generate -DgroupId=com.express.it.arch.poc.osgi \
                                                 -DartifactId=osgipoc \
                                                 -DarchetypeArtifactId=maven-archetype-quickstart \
                                                 -DinteractiveMode=false
[INFO] Scanning for projects...



[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.924 s
[INFO] Finished at: 2016-12-14T13:53:54-05:00
[INFO] Final Memory: 15M/149M
[INFO] ------------------------------------------------------------------------
[esb@cmhlcarchapp01 poc]$

Create an Activator class in your newly created directory tree that matches the name in your pom.xml. Please note that we added additional code to show when the bundle was activated, as we initially had issues getting this to work. This is, of course, not production ready, but we retained it as it is just a simple POC.

package com.express.it.arch.poc.osgi;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintStream;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator
  implements BundleActivator
{
  public void start(BundleContext context)
  {
    try
    {
      FileWriter fw = new FileWriter(new File("/tmp/foo.txt"));
      fw.write("test");
      fw.close();
    }
    catch (Exception localException) {}
    System.out.println("Starting the bundle");
  }

  public void stop(BundleContext context)
  {
    System.out.println("Stopping the bundle");
  }
}

The base pom.xml for this example is shown below…




    4.0.0

    com.express.it.arch.poc.osgi
    osgipoc
    1.0
    bundle

    com.express.it.arch.poc.osgi Bundle
    com.express.it.arch.poc.osgi POC bundle project.

   
     2.15.1
   

   
      
         org.osgi
         org.osgi.core
         4.2.0
         provided
      

      
         org.apache.camel
         camel-blueprint
         ${version}
      

      
         org.apache.camel
         camel-core
         ${version}
      
   

   
      install
        
            
                org.apache.felix
                maven-bundle-plugin
                2.3.7
                true
                
                  
                    ${project.artifactId}
                    ${project.version}
                    com.express.it.arch.poc.osgi.Activator
                    
                       com.express.it.arch.poc.osgi*;version=${project.version}
                    
                    
                      *
                    
                  
                
            
         
            org.apache.maven.plugins
            maven-compiler-plugin
         

         
            org.apache.maven.plugins
            maven-resources-plugin
         

         
            org.codehaus.mojo
            build-helper-maven-plugin
         

         
            org.codehaus.mojo
            versions-maven-plugin
         
        
    

Create a simple route in a camel context file with what is below, creating the noted location under your project directory…

[esb@cmhlcarchapp01 fuse]$ cat src/main/resources/OSGI-INF/blueprint/camel-context.xml



   
      
         
      
   

   
      
         
         
         
            ${id}
         
         
            
         
      
   


After doing what is above and placing the contents of the pom.xml in the prebuilt pom.xml, build the project from the osgipoc directory with the following…

mvn install

Create a properties file under your Fuse installation in the etc directory. Name the file whatever the persistentID is above, in our case, mypack.cfg.

[esb@cmhlcarchapp01 fuse]$ cat etc/mypack.cfg
in.endpoint = file:foo2
out.endpoint = file:bar2
[esb@cmhlcarchapp01 fuse]$

Create a “features” file with the following contents, changing the location to wherever you want to place the generated jar file…

[esb@cmhlcarchapp01 fuse]$ cat osgipoc.xml

  
    file:///opt/fuse/osgipoc.jar
  

Then copy the generated jar file to this location, and install the bundle in Karaf with what is below…

[esb@cmhlcarchapp01 fuse]$ bin/client
JBossFuse:admin@root> features:addurl file:///opt/fuse/osgipoc.xml
JBossFuse:admin@root> features:install osgipoc
JBossFuse:admin@root> osgi:list | grep poc.osgi
[ 357] [Active     ] [Created     ] [       ] [   80] com.express.it.arch.poc.osgi Bundle (1.0)
JBossFuse:admin@root>

Navigate to the base of your Fuse directory, and create a file in the foo2 directory. You should see it immediately copied to the bar2 directory.

Our next example will include additional java code that contains a route and additional business logic.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.