Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
2.3. Working with Camel on JBoss EAP
Here are some basic examples that describe how the Camel subsystem interacts with JBoss EAP configuration files.
Note
For more working examples of the Camel subsystem and JBoss EAP, see the quickstarts provided with JBoss EAP.
2.3.1. Using a Camel Context 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The
camelContext
represents a single Camel routing rulebase. It contains all the routes of your application. You can have as many camelContexts as necessary, provided they have different names.
Camel on EAP allows you to:
- define a
camelContext
as a part of the subsystem definition in thestandalone.xml
anddomain.xml
files - deploy them in a supported deployment artifact that includes the
-camel-context.xml
suffixed file - provide camelContexts along with their routes via a RouteBuilder and the CDI integration
You can configure a
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Also, you can consume a defined
camelContext
as a part of the subsystem definition this way:
camelContext
two ways:
- using annotation
@Inject
viacamel-cdi
- via JNDI treeImportantTo inject by CDI a deployed
camelContext
defined in Spring XML, you need to use the Java@Resource
annotation, instead of the@Inject @ContextName
annotations in the Camel CDI extension. Using the@Inject @ContextName
annotations can result in the creation of a newcamelContext
instead of injecting the named context, which later causes endpoint lookups to fail.
2.3.1.1. Example of a Context and a Route 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following example, describes a context along with an associated route provided via CDI and a RouteBuilder. It displays an application scoped bean that starts automatically, when you start an application. The
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
@ContextName
annotation provides a specific name to the CamelContext.
2.3.1.2. Configuring Camel Context using CDI Mechanism 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Camel CDI automatically deploys and configures a
CamelContext
bean. After you initialise the CDI container, a CamelContext bean starts and instantiates automatically.
You can inject a
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
CamelContext
bean into the application as:
@Inject @ContextName("cdi-context") private CamelContext context;
@Inject
@ContextName("cdi-context")
private CamelContext context;
2.3.1.3. Configuring Camel Routes using CDI Mechanism 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
After you initialise the CDI container, Apache Camel CDI automatically collects all the RouteBuilder beans in the application, instantiates and adds them to the CamelContext bean instance.
For example, you can add a camel route and declare a class in the following way:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
2.3.1.4. Customizing Camel Context 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Apache Camel CDI provides
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
@ContextName
qualifier that allows you to change the name of the default CamelContext bean. For example:
Note
You can use any
CamelContext
class to declare a custom camel context bean.
2.3.1.5. Supporting Multiple CamelContexts 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
You can declare any number of CamelContext beans in your application. The CDI qualifiers declared on these CamelContext beans are used to bind the Camel routes and other Camel primitives to the corresponding Camel contexts.
The CDI qualifiers declared on the CamelContext beans are also used to bind the corresponding Camel primitives. For example:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
2.3.2. Camel Context Deployment 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
You can deploy a Camel context to JBoss EAP two ways:
- Use the
-camel-context.xml
suffix as a part of another supported deployment, such as a JAR, WAR, or EAR deploymentThis deployment may contain multiple-camel-context.xml
files. - Use the
-camel-context.xml
suffix in a standaloneXML
file deployment by dropping the file into the EAP deployment directory
A deployed Spring-based Camel context is CDI injectable as:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
In this example, the string
@Resource(name = "java:jboss/camel/context/mycontext") CamelContext camelContext;
@Resource(name = "java:jboss/camel/context/mycontext")
CamelContext camelContext;
java:jboss/camel/context/mycontext
is the name assigned the deployed camel context in the JNDI registry. mycontext
is the xml:id
of the camelContext
element in the Camel context XML file.
2.3.3. Hawtio Web Console 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
HawtIO is a web application that runs in a JVM. You can start Hawtio on your machine:
- deploy HawtIO as a WAR file
- add some users to your management and application realms by using the following command: $ bin/add-user.sh
- navigate to the
http://localhost:8080/hawtio
, the HawtIO login page appears - Clickin the top navigation bar to view all the running Camel Contexts
Apache Camel plugin allows you to browse all the running Camel applications in the current JVM. You can also view the following details:
- list of all the running camel applications
- detail information of each CamelContext such as Camel version number, runtime statics
- list of all the routes and their runtime statistics in each camel application
- manage the lifecycle of all camel applications and their routes
- graphical representation of the running routes along with real time metrics
- live tracing and debugging of running routes
- profile the running routes with real time runtime statics
- browse and send messages to camel endpoint
2.3.4. Selecting Components 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
If you add nested component or component-module XML elements, then instead of the default list of Camel components, only the specified elements will be added to your deployment.
For example:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
2.3.5. Configuring Camel Subsystem 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The Camel subsystem configuration may contain static system routes. However, these routes are started automatically.
2.3.6. Configuring Camel Deployment 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To make changes in the default configuration of your Camel deployment, you can edit either
WEB-INF/jboss-all.xml
or META-INF/jboss-all.xml
configuration file.
Use a jboss-camel XML element within the
jboss-all.xml
file, to control the camel configuration.