Install and deploy bundle in JBoss FUSE OSGi container

Jboss FUSE is an OSGi container based on Karaf (Felix) framework. In this tutorial, we will learn how to set up Jboss Fuse and deploy a bundle in it.

Download

  1. Go to the Jboss site and download  “JBoss Fuse for Developers”  and  “JBoss Fuse Developer Tooling”. Please note that you may need to have an account with Red Hat before you can download these products. Please follow the instructions in the site. Download  “Stand-alone Installer” for Jboss Developer Studio.
  2. Unzip Jboss Fuse in your favorite directory. We would refer this location as FUSE_HOME. Open <FUSE_HOME>/etc/user.properties and uncomment admin property.
  3. Open <FUSE_HOME>/etc/org.apache.karaf.management.cfg and change the value of rmiRegistryHost to 127.0.0.1.
  4. Go to <FUSE_HOME>/etc/org.ops4j.pax.url.mvn.cfg and set the property value org.ops4j.pax.url.mvn.localRepository=${user.home}/.m2/repository. Please note that your local maven repository location may be different. Please change accordingly. Now, Fuse is ready to use.
  5. Follow the instructions of Standalone installer and start the eclipse based JBoss Developer Studio.
  6. On the Welcome page, click on tab “Software Update”. If you don’t see Jboss Fuse Development in the list, please check if it is already installed.

Jboss Tool Fuse Development

7. Click on “Install/Update” and restart JBoss Developer Studio when asked for.

Create Bundle

8. After update is completed, go to New > Other > Fuse Tooling > Fuse Project

JBossDeveloperStudioFuseProject

9.  Provide a Project name and click Next.

10. Select the archetype “org.apache.camel.archetypes:camel-archetype-blueprint:” Fill in the details of Group Id.

JbossFuseCamelArchtype

11. Click on Finish and you have a deployable fuse bundle project ready.

Jboss Fuse First Bundle

Project Artifacts

 1. Method interface

file: Hello.java

package com.javanbeyond.camel.blueprint;

/**
 * An interface for implementing Hello services.
 */
public interface Hello {

    String hello();
    
}

2. Interface implementation or Bean class

file: HelloBean.java. This class will be referred in blueprint.xml as a bean.

package com.javanbeyond.camel.blueprint;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * A bean which we use in the route
 */
public class HelloBean implements Hello {

    private String say = "Hello World";

    // This method will be called from camel context
    public String hello() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return say + " at " + sdf.format(new Date());
    }

    public String getSay() {
        return say;
    }

    public void setSay(String say) {
        this.say = say;
    }
}

3. Blueprint configuration
file: blueprint.xml. This is the declarative configuration file of the bundle which instructs the blueprint container to parse, instantiate and wire the components inside the blueprint.xml together.

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="        http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd        http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
    <!-- bean class declaration -->
    <bean id="helloBean" class="com.javanbeyond.camel.blueprint.HelloBean">
        <property name="say" value="Hi from Camel"></property>
    </bean>
    <!-- The routing logic is written in Camel Context -->
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route id="timerToLog">
            <from uri="timer:foo?period=5000"></from>
            <setBody>
                <method ref="helloBean" method="hello"></method>
            </setBody>
            <log message="The message contains ${body}" loggerRef="helloBean"></log>
            <to uri="mock:result?expectedCount=2&amp;resultMinimumWaitTime=3&amp;retainFirst=3"></to>
        </route>
    </camelContext>
</blueprint>

Deploy

12. Run maven clean and install on the project in Developer Studio.

13. Go to <FUSE_HOME>/bin directory and execute fuse.bat or fuse.

14. Once fuse starts, type the command “osgi:install mvn:com.javanbeyond/camel-blueprint/1.0.0-SNAPSHOT” on the FUSE console and you should get a <BUNDLE_ID>.

15. Type “osgi:start <BUNDLE_ID>”

16. Type “osgi:list” and you should see your bundle started.

[ 286] [Active  ] [Created        ] [       ] [   80] Camel Blueprint Route (1.0.0.SNAPSHOT)

Bundle in Action

17. Type “log:tail” and every 5 second, the timer component logs the message body to console. The message body is the same message we set in our camel context.

2015-10-03 21:38:03,301 | INFO  | #0 - timer://foo | timerToLog                       | ?                                   ? | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | The message contains Hi from Camel at 2015-10-03 21:38:03
2015-10-03 21:38:08,294 | INFO  | #0 - timer://foo | timerToLog                       | ?                                   ? | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | The message contains Hi from Camel at 2015-10-03 21:38:08
2015-10-03 21:38:13,296 | INFO  | #0 - timer://foo | timerToLog                       | ?                                   ? | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | The message contains Hi from Camel at 2015-10-03 21:38:13
2015-10-03 21:38:18,300 | INFO  | #0 - timer://foo | timerToLog                       | ?                                   ? | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | The message contains Hi from Camel at 2015-10-03 21:38:18

18. Open browser and type “http://localhost:8181”. This is management console. Type in the username and password as in <FUSE_HOME>/etc/user.properties.  Click on “Camel” tab and open “Camel Contexts”. You should see the statistics of your camel context.

Fuse Management Console

 

Back to Top