Chapter 10. OSGi Bundle Tutorials
10.1. Generating and Running an EIP Bundle
- Maven installation—Maven is a free, open source build tool from Apache. You can download the latest version from http://maven.apache.org/download.html (minimum is 3.x).
- Internet connection—whilst performing a build, Maven dynamically searches external repositories and downloads the required artifacts on the fly. In order for this to work, your build machine must be connected to the Internet.
- fusesource Maven repository is configured—in order to locate the archetypes, Maven's
settings.xmlfile must be configured with the location of the
fusesourceMaven repository. For details of how to set this up, see the section called “Adding the Red Hat JBoss Fuse repository”.
Generating an EIP bundle
karaf-camel-cbr-archetypearchetype creates a router project, which is configured to deploy as a bundle. To generate a Maven project with the coordinates,
org.fusesource.example:camel-bundle, enter the following command:
mvn archetype:generate \ -DarchetypeGroupId=io.fabric8.archetypes \ -DarchetypeArtifactId=karaf-camel-cbr-archetype \ -DarchetypeVersion=1.2.0.redhat-630187 \ -DgroupId=org.fusesource.example \ -DartifactId=camel-bundle \ -Dversion=1.0-SNAPSHOT \ -Dfabric8-profile=camel-bundle-profile
\, indicates line continuation on Linux and UNIX operating systems. On Windows platforms, you must omit the backslash character and put all of the arguments on a single line.
ProjectDir/camel-bundle, containing the files for the generated bundle project.
Running the EIP bundle
camel-bundleproject, perform the following steps:
- Build the project—open a command prompt and change directory to
ProjectDir/camel-bundle. Use Maven to build the demonstration by entering the following command:
mvn installIf this command runs successfully, the
ProjectDir/camel-bundle/targetdirectory should contain the bundle file,
camel-bundle.jarand the bundle will also be installed in the local Maven repository.
- Install prerequisite features (optional)—by default, the
camel-corefeature and some related features are pre-installed in the OSGi container. But many of the Apache Camel components are not installed by default. To check which features are available and whether or not they are installed, enter the following console command:
JBossFuse:karaf@root> features:listApache Camel features are identifiable by the
camel-prefix. For example, if one of your routes requires the HTTP component, you can make sure that it is installed in the OSGi container by issuing the following console command:
JBossFuse:karaf@root> features:install camel-http
- Install and start the camel-bundle bundle—at the Red Hat JBoss Fuse console, enter the following command to install the bundle from the local Maven repository (see Section A.3, “Mvn URL Handler”):
JBossFuse:karaf@root> osgi:install -s mvn:org.fusesource.example/camel-bundle/1.0-SNAPSHOT
- Provide the route with file data to process—after the route has started, you should find the following directory under your JBoss Fuse installation:
InstallDir/work/cbr/inputTo initiate content routing in this example, copy the provided data files from the
ProjectDir/camel-bundle/src/main/fabric8/datadirectory into the
- View the output—after a second or two, the data files disappear from the
work/cbr/inputdirectory, as the route moves the data files into various sub-directories of the
- Stop the camel-bundle bundle—to stop the
camel-bundlebundle, you first need to discover the relevant bundle number. To find the bundle number, enter the following console command:
JBossFuse:karaf@root> osgi:listAt the end of the listing, you should see an entry like the following:
[ 265] [Active ] [Created ] [ ] [ 80] JBoss Fuse Quickstart: camel-cbr (1.0.0.SNAPSHOT)Where, in this example, the bundle number is 265. To stop this bundle, enter the following console command:
JBossFuse:karaf@root> osgi:stop 265