此内容没有您所选择的语言版本。

Chapter 13. FAB Tutorial


Abstract

This tutorial describes a complete example of how to generate, build, run, and deploy a Apache Camel application as a FAB.

13.1. Generating and Running an EIP FAB

Overview

This section explains how to generate, build, and run a complete Apache Camel example as a FAB, where the starting point code is generated with the help of a Maven archetype.

Prerequisites

In order to generate a project using an Red Hat JBoss Fuse Maven archetype, you must have the following prerequisites:
  • 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 2.0.9).
  • 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.xml file must be configured with the location of the fusesource Maven repository. For details of how to set this up, see the section called “Adding the Red Hat JBoss Fuse repository”.

Generating an EIP FAB

The camel-archetype-blueprint archetype creates a sample Maven project that can be deployed as a FAB. To generate a Maven project with the coordinates, org.fusesource.example:camel-fab, enter the following command:
mvn archetype:generate
-DarchetypeGroupId=org.apache.camel.archetypes
-DarchetypeArtifactId=camel-archetype-blueprint
-DarchetypeVersion=2.12.0.redhat-610379
-DgroupId=org.fusesource.example
-DartifactId=camel-fab
Copy to Clipboard Toggle word wrap
The result of this command is a directory, ProjectDir/camel-fab, containing the files for the generated FAB project.

Modify the POM file

By default, the generated project's POM is configured as an OSGi bundle, not a FAB. To convert the camel-fab/pom.xml file to a FAB POM, modify it as follows:
  1. Open the camel-fab/pom.xml file with your favorite text editor and change the packaging type from bundle to jar, as follows:
      <groupId>org.fusesource.example</groupId>
      <artifactId>camel-fab</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
    Copy to Clipboard Toggle word wrap
  2. Add the provided scope to all of the dependencies (except for the dependencies that are already marked with test scope). Scroll down to the dependencies element and add a scope element to each of the dependencies as shown:
      ...
      <dependencies>
        <dependency>
          <groupId>org.apache.camel</groupId>
          <artifactId>camel-core</artifactId>
          <version>2.12.0.redhat-610346</version>
     <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.camel</groupId>
          <artifactId>camel-blueprint</artifactId>
          <version>2.12.0.redhat-610346</version>
     <scope>provided</scope>
        </dependency>
        ...
    Copy to Clipboard Toggle word wrap
  3. Remove the Maven bundle plug-in configuration. Scroll down to the plugins section and remove the complete plugin element corresponding to the maven-bundle-plugin plugin.
  4. Save and close the camel-fab/pom.xml file.

Running the EIP FAB

To install and run the generated camel-fab project, perform the following steps:
  1. Build the project—open a command prompt and change directory to ProjectDir/camel-fab. Use Maven to build the demonstration by entering the following command:
    mvn install
    Copy to Clipboard Toggle word wrap
    If this command runs successfully, the ProjectDir/camel-fab/target directory should contain the JAR file, camel-fab-1.0-SNAPSHOT.jar and the JAR will also be installed in the local Maven repository.
  2. Install the fabric-bundle feature—the fabric-bundle feature is a prerequisite for using FABs. If it is not already installed, enter the following command:
    JBossFuse:karaf@root> features:install fabric-bundle
    Copy to Clipboard Toggle word wrap
  3. Install and start the camel-fab JAR—at the Red Hat JBoss Fuse console, enter the following command:
    JBossFuse:karaf@root> install fab:mvn:org.fusesource.example/camel-fab
    Copy to Clipboard Toggle word wrap
    Note
    It can take a minute or so for the install command to finish, because the FAB runtime needs some time to evaluate the tree of dependencies associated with the camel-fab artifact.
    If the FAB is successfully installed, its bundle ID is logged to the console window. Using this bundle ID, bundleID, start the FAB by entering the following console command:
    JBossFuse:karaf@root> fab:start bundleID
    Copy to Clipboard Toggle word wrap
  4. View the log—After entering the fab:start command, the Camel route starts to log messages to the container's log. To view the log, enter the following command:
    JBossFuse:karaf@root> log:tail -n 10
    Copy to Clipboard Toggle word wrap
    You should see messages like the following:
    2014-02-24 10:53:02,175 | INFO  | #0 - timer://foo | timerToLog
    | rg.apache.camel.util.CamelLogger  176 | 136
    - org.apache.camel.camel-core - 2.12.0.redhat-610349
    | The message contains Hi from Camel at 2014-02-24 10:53:02
    2014-02-24 10:53:07,175 | INFO  | #0 - timer://foo | timerToLog
    | rg.apache.camel.util.CamelLogger  176 | 136
    - org.apache.camel.camel-core - 2.12.0.redhat-610349
    | The message contains Hi from Camel at 2014-02-24 10:53:07
    Copy to Clipboard Toggle word wrap
    To exit the log, type Ctrl-C.
  5. Stop the camel-fab bundle—using the FAB's bundle ID, bundleID, stop the camel-fab bundle, as follows:
    JBossFuse:karaf@root> fab:stop bundleID
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat