此内容没有您所选择的语言版本。
Chapter 2. Building Your Application on JBoss EAP
This chapter summarizes you how you can set up the Hello World project using the camel-cdi
component with Red Hat Fuse on JBoss EAP.
2.1. Overview 复制链接链接已复制到粘贴板!
The following example demonstrates the use of camel-cdi
component with Red Hat Fuse on EAP to integrate CDI beans with Camel routes.
In this example, a Camel route takes a message payload from a servlet HTTP GET request and passes it on to a direct endpoint. It then passes the payload onto a Camel CDI bean invocation to produce a message response and displays the output on the web browser page.
2.2. Running the Project 复制链接链接已复制到粘贴板!
Before running the project, ensure that your set up includes maven and the application server with Red Hat Fuse. Perform the following steps to run your project:
Start the application server in standalone mode:
-
For Linux:
${JBOSS_HOME}/bin/standalone.sh -c standalone-full.xml
-
For Windows:
%JBOSS_HOME%\bin\standalone.bat -c standalone-full.xml
-
For Linux:
-
Build and deploy the project:
mvn install -Pdeploy
-
Now, browse to
http://localhost:8080/example-camel-cdi/?name=World
location. The following messageHello World
appears as an output on the web page. Also, you can view the Camel Route as:
from("direct:start").beanRef("helloBean");
from("direct:start").beanRef("helloBean");
The beanRef
DSL makes Camel look for a bean named helloBean
in the bean registry. Also, the bean is available to Camel due to the SomeBean
class. By using the @Named
annotation, the camel-cdi
adds the bean to the Camel bean registry.
2.3. BOM file for JBoss EAP 复制链接链接已复制到粘贴板!
The purpose of a Maven Bill of Materials (BOM) file is to provide a curated set of Maven dependency versions that work well together, saving you from having to define versions individually for every Maven artifact.
The Fuse BOM for JBoss EAP offers the following advantages:
- Defines versions for Maven dependencies, so that you do not need to specify the version when you add a dependency to your POM.
- Defines a set of curated dependencies that are fully tested and supported for a specific version of Fuse.
- Simplifies upgrades of Fuse.
Only the set of dependencies defined by a Fuse BOM are supported by Red Hat.
To incorporate a BOM file into your Maven project, specify a dependencyManagement
element in your project’s pom.xml
file (or, possibly, in a parent POM file), as shown in the following example:
The org.jboss.redhat-fuse
BOM is new in Fuse 7.0 and has been designed to simplify BOM versioning. The Fuse quickstarts and Maven archetypes still use the old style of BOM, however, as they have not yet been refactored to use the new one. Both BOMs are correct and you can use either one in your Maven projects. In an upcoming Fuse release, the quickstarts and Maven archetypes will be refactored to use the new BOM.
After specifying the BOM using the dependency management mechanism, it becomes possible to add Maven dependencies to your POM without specifying the version of the artifact. For example, to add a dependency for the camel-velocity
component, you would add the following XML fragment to the dependencies
element in your POM:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-velocity</artifactId> <scope>provided</scope> </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-velocity</artifactId>
<scope>provided</scope>
</dependency>
Note how the version
element is omitted from this dependency definition.