Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update tutorial to run camel on Apache Felix Karaf 1.0.0

...

Code Block
xml
xml
titleCamelContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       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-2.5.xsd
       http://activemqcamel.apache.org/camel/schema/spring
       http://activemqcamel.apache.org/camel/schema/spring/camel-spring-2.0.0.xsd">

  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
      <from uri="timer://myTimer?fixedRate=true&amp;period=10000"/>
      <bean ref="myTransform" method="transform"/>
      <to uri="log:ExampleRouter"/>
    </route>
  </camelContext>
</beans>

...

Run the command mvn clean install org.ops4j:maven-pax-plugin:eclipse (= Repeat step #5).

Step 8 : Deploy the bundles

We will show you now that we can easily deploy our bundles in two OSGI servers running a different OSGI kernel:

  • Felix for ServiceMix Kernel
  • Equinox for Spring Dynamic Module

ServiceMix Kernel

As mentioned in the documentation, Apache ServiceMix Kernel is a small OSGi based runtime which provides a lightweight container onto which various components and applications can be deployed. Moreover, the server provides administration, security, logging and provisioning features who will help you during the deployment and administration steps.

If this is not yet done, download ServiceMix Kernel 1.1.0 server and install it. Launch the server by executing the command in the bin folder:

Code Block

c:\apache-servicemix-kernel-1.1.0\bin>servicemix

If this is the first time Servicemix is started, then you will see that a new data folder is created.

In order to allow our bundles to work with Camel, execute the following commands to download and install the 'Camel and Spring bundles':

Code Block

servicemix> osgi install \-s mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.activation-api-1.1/1.2.0
servicemix> osgi install \-s mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.1/1.2.0
servicemix> osgi install \-s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-impl/2.1.6_1
servicemix> osgi install \-s mvn:org.springframework/spring-tx/2.5.6
servicemix> osgi install \-s mvn:org.apache.camel/camel-core/1.6.0
servicemix> osgi install \-s mvn:org.apache.camel/camel-spring/1.6.0
servicemix> osgi install \-s mvn:org.apache.camel/camel-osgi/1.6.0

and check that the MANIFEST file created looks like the following :

Code Block

Manifest-Version: 1.0
Bundle-Version: 0.1
Build-Jdk: 1.6.0_16
Built-By: Charlesm
Tool: Bnd-0.0.255
Bnd-LastModified: 1256906516718
Bundle-Name: demo.camel-bundle [demo.camel]
Bundle-ManifestVersion: 2
Created-By: Apache Maven Bundle Plugin
Import-Package: demo.service;version="0.1"
Bundle-SymbolicName: demo.camel-bundle

The most important point that we see in this file is that we will import the package demo.service allowing Camel mediation router to have access to the service Transform exposed as an OSGI service by the bundle demo.service.

Step 8 : Deploy the bundles

We will show you now that we can easily deploy our bundles in two OSGI servers running a different OSGI kernel:

  • Apache Felix Karaf
  • Equinox for Spring Dynamic Module

Apache Felix Karaf

As mentioned in the documentation, Apache Felix Karaf is a small OSGi based runtime which provides a lightweight container onto which various components and applications can be deployed. Moreover, the server provides administration, security, logging and provisioning features who will help you during the deployment and administration steps.

Here is the list of features provided by the osgi server :

  • Hot deployment: Karaf supports hot deployment of OSGi bundles by monitoring jar files inside the home/deploy directory. Each time a jar is copied in this folder, it will be installed inside the runtime. You can then update or delete it and changes will be handled automatically. In addition, the Karaf also supports exploded bundles and custom deployers (blueprint and spring ones are included by default).
  • Dynamic configuration: Services are usually configured through the ConfigurationAdmin OSGi service. Such configuration can be defined in Karaf using property files inside the home/etc directory. These configurations are monitored and changes on the properties files will be propagated to the services.
  • Logging System: using a centralized logging back end supported by Log4J, Karaf supports a number of different APIs (JDK 1.4, JCL, SLF4J, Avalon, Tomcat, OSGi)
  • Provisioning: Provisioning of libraries or applications can be done through a number of different ways, by which they will be downloaded locally, installed and started.
  • Native OS integration: Karaf can be integrated into your own Operating System as a service so that the lifecycle will be bound to your Operating System.
  • Extensible Shell console: Karaf features a nice text console where you can manage the services, install new applications or libraries and manage their state. This shell is easily extensible by deploying new commands dynamically along with new features or applications.
  • Remote access: use any SSH client to connect to Karaf and issue commands in the console
  • Security framework based on JAAS
  • Managing instances: Karaf provides simple commands for managing multiple instances. You can easily create, delete, start and stop instances of Karaf through the console.
  • Supports the latest OSGi 4.2 containers: Apache Felix Framework 2.0.0 and Eclipse Equinox 3.5

If this is not yet done, download Apache Felix Karaf 1.0.0 server and install it. Launch the server by executing the command in the bin folder:

Code Block

c:\apache-felix-karaf-1.0.0\bin>karaf

If this is the first time that Karaf is started, then you will see that a new data folder is created under the root folder. This folder will contain the bundles installed at the startup of the server

In order to allow our bundles (demo.service and demo.camel) to work with Apache Camel framework, execute the following commands to download and install the 'Camel and Spring bundles':

1. Add camel feature file

Code Block

karaf@root> features:addUrl mvn:org.apache.camel.karaf/features/2.0.0/xml/features

This new feature file contains the list of camel bundles to be installed. This will avoid that you install each required bundle (= jar) separately though the command osgi:install

2. Install bundles using feature command

Code Block

karaf@root> features:install spring
karaf@root> features:install spring-dm
karaf@root> features:install camel-core
karaf@root> features:install camel-spring
karaf@root> features:install camel-osgi

Verify that your list of bundles is complete using command osgi:list

Code Block

karaf@root> osgi:list
START LEVEL 100
   ID   State         Blueprint      Level  Name
[   0] [Active     ] [            ] [    0] System Bundle (2.0.0)
[   1] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell Various Commands (1.0.0)
[   2] [Active     ] [            ] [   30] Apache MINA Core (2.0.0.M6)
[   3] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell PackageAdmin Commands (1.0.0)
[   4] [Active     ] [Created     ] [   30] Apache Felix Karaf :: JAAS Modules (1.0.0)
[   5] [Active     ] [Created     ] [   30] Apache Felix Karaf :: JAAS Config (1.0.0)
[   6] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Blueprint Deployer (1.0.0)
[   7] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell Admin (1.0.0)
[   8] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell Log Commands (1.0.0)
[   9] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Features Command (1.0.0)
[  10] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell SSH (1.0.0)
[  11] [Active     ] [            ] [   30] Apache Mina SSHD :: Core (0.2.0)
[  12] [Active     ] [            ] [   30] Apache Felix Gogo Shell Runtime (0.2.0)
[  13] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Features Core (1.0.0)
[  14] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Management (1.0.0)
[  15] [Active     ] [            ] [   30] org.osgi.impl.bundle.jmx (4.2.0.200907080519)
[  16] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell Console (1.0.0)
[  17] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell OSGi Commands (1.0.0)
[  18] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Features Management (1.0.0)
[  19] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Spring Deployer (1.0.0)
[  20] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Features Deployer (1.0.0)
[  21] [Active     ] [Created     ] [   30] Apache Felix Karaf :: Shell ConfigAdmin Commands (1.0.0)
[  22] [Active     ] [            ] [   10] Apache Felix File Install (2.0.0)
[  23] [Active     ] [            ] [   10] Apache Felix Prefrences Service (1.0.2)
[  24] [Active     ] [            ] [   10] Apache Felix Configuration Admin Service (1.2.4)
[  25] [Active     ] [            ] [    8] OPS4J Pax Logging - API (1.4)
[  26] [Active     ] [            ] [    8] OPS4J Pax Logging - Service (1.4)
[  27] [Active     ] [            ] [    5] OPS4J Pax Url - mvn: (1.0.0)
[  28] [Active     ] [            ] [    5] OPS4J Pax Url - wrap: (1.0.0)
[  29] [Active     ] [Created     ] [   20] Apache Geronimo Blueprint Bundle (1.0.0)
[  32] [Active     ] [            ] [   60] Apache ServiceMix Bundles: aopalliance-1.0 (1.0.0.1)
[  33] [Active     ] [            ] [   60] Spring Core (2.5.6.SEC01)
[  34] [Active     ] [            ] [   60] Spring Beans (2.5.6.SEC01)
[  35] [Active     ] [            ] [   60] Spring AOP (2.5.6.SEC01)
[  36] [Active     ] [            ] [   60] Spring Context (2.5.6.SEC01)
[  37] [Active     ] [            ] [   60] Spring Context Support (2.5.6.SEC01)
[  38] [Active     ] [            ] [   60] Apache ServiceMix Bundles: cglib-2.1_3 (2.1.0.3_2)
[  39] [Active     ] [            ] [   60] spring-osgi-io (1.2.0)
[  40] [Active     ] [            ] [   60] spring-osgi-core (1.2.0)
[  41] [Active     ] [            ] [   60] spring-osgi-extender (1.2.0)
[  42] [Active     ] [            ] [   60] spring-osgi-annotation (1.2.0)
[  43] [Active     ] [            ] [   60] Java Activation API (1.1.1)
[  44] [Active     ] [            ] [   60] Apache ServiceMix Specs :: JAXB API 2.1 (1.3.0)
[  45] [Active     ] [            ] [   60] Apache ServiceMix Specs :: STAX API 1.0 (1.3.0)
[  46] [Active     ] [            ] [   60] Apache ServiceMix Bundles: jaxb-impl-2.1.6 (2.1.6.1)
[  47] [Active     ] [            ] [   60] camel-core (2.0.0)
[  48] [Active     ] [            ] [   60] geronimo-jta_1.1_spec (1.1.1)
[  49] [Active     ] [            ] [   60] Spring AOP (2.5.6)
[  50] [Active     ] [            ] [   60] Spring Beans (2.5.6)
[  51] [Active     ] [            ] [   60] Spring Core (2.5.6)
[  52] [Active     ] [            ] [   60] Spring Context (2.5.6)
[  53] [Active     ] [            ] [   60] Spring Transaction (2.5.6)
[  54] [Active     ] [            ] [   60] camel-spring (2.0.0)
[  55] [Active     ] [            ] [   60] camel-osgi (2.0.0)

Next, copy the our Next, copy the two jar into the deploy folder, first the service and next the Camel bundle.

...

Code Block
servicemix> osgi :install \-s mvn:demo.service/demo.service-bundle/0.1
servicemix> osgi :install \-s mvn:demo.camel/demo.camel-bundle/0.1

After a few seconds, you should see on the Servicemix Karaf log console the following text:

...

  • In case of trouble, use the command: osgi:list to see if all the deployed bundles are installed correctly and have their status equals to active
  • To see the log of ServiceMixKaraf, use the command: log d:display

Spring DM server

Spring DM server compare to ServiceMix Kernel, Eclipse Equinox or Apache Felix is much more than a OSGI server. This is a completely module-based Java application server that is designed to run enterprise Java applications and Spring-powered applications with a new degree of flexibility and reliability. It offers a simple yet comprehensive platform to develop, deploy, and service enterprise Java applications.

...