Red Hat Training

A Red Hat training course is available for Red Hat Fuse

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.
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 the standalone.xml and domain.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 camelContext as a part of the subsystem definition this way:
       <from uri="direct:start"/>
         <simple>Hello #{body}</simple>
Also, you can consume a defined camelContext two ways:
  • using annotation @Inject via camel-cdi
  • via JNDI tree
    To 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 new camelContext instead of injecting the named context, which later causes endpoint lookups to fail. 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 @ContextName annotation provides a specific name to the CamelContext.
public class HelloRouteBuilder extends RouteBuilder {

    HelloBean helloBean;

    public void configure() throws Exception {
        from("direct:start").transform(body().prepend(helloBean.sayHello()).append(" user."));
} 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 CamelContext bean into the application as:
    private CamelContext context; 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:
class MyRouteBean extends RouteBuilder {
    public void configure() {
  } Customizing Camel Context

Apache Camel CDI provides @ContextName qualifier that allows you to change the name of the default CamelContext bean. For example:
class CustomCamelContext extends DefaultCamelContext {
    void customize() {
        // Set the Camel context name
        // Disable JMX
    void cleanUp() {
        // ...
You can use any CamelContext class to declare a custom camel context bean. 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:
ProducerTemplate producerTemplate;
MockEndpoint outbound; // URI defaults to the member name, i.e. mock:outbound
Endpoint endpoint;

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 deployment
    This deployment may contain multiple -camel-context.xml files.
  • Use the -camel-context.xml suffix in a standalone XML file deployment by dropping the file into the EAP deployment directory
A deployed Spring-based Camel context is CDI injectable as:
@Resource(name = "java:jboss/camel/context/mycontext")
CamelContext camelContext;
In this example, the string 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/
  • navigate to the http://localhost:8080/hawtio, the HawtIO login page appears
  • Click Camel in 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:
<jboss umlns="urn:jboss:1.0">
    <jboss-camel xmlns="urn:jboss:jboss-camel:1.0">
        <component name="camel-ftp"/>
        <component-module name="org.apache.camel.component.rss"/>

2.3.5. Configuring Camel Subsystem

The Camel subsystem configuration may contain static system routes. However, these routes are started automatically.
    <from uri="direct:start"/>
        <simple>Hello #{body}</simple>

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.