StackLeader Blog

Post Image
Apr 11, 2017

Getting started with camel-cdi on EAP 7


The Apache Camel CDI component was updated in 2.17 to integrate more seemlessly with CDI. This post shows an example of how to get started defining routes using the java dsl with the use of the camel-cdi component.


The source code for this example is available on github.


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

    <name>EAP 7 Camel  :: example</name>


Defining a Camel Route

Create an application scoped class extending org.apache.camel.builder.RouteBuilder and use the camel-cdi org.apache.camel.cdi.ContextName annotation to provide the camel context reference.

package com.stackleader.camel.example;

import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.ContextName;

 * @author dcnorris
public class CamelRunner extends RouteBuilder {

    public void configure() throws Exception {
                .log("Hello ${body}");


The above route will simply log the message “Hello Camel” every 5 seconds.


11:39:56,967 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0003: Processing weld deployment camel-cdi-eap-1.0.0.war
11:39:57,020 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-5) HV000001: Hibernate Validator 5.2.4.Final-redhat-1
11:39:57,158 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) WFLYWELD0006: Starting Services for CDI deployment: camel-cdi-eap-1.0.0.war
11:39:57,183 INFO  [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900: 2.3.3 (redhat)
11:39:57,213 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0009: Starting weld service for deployment camel-cdi-eap-1.0.0.war
11:39:57,373 INFO  [org.jboss.weld.Event] (MSC service thread 1-3) WELD-000411: Observer method [BackedAnnotatedMethod] private org.apache.camel.cdi.CdiCamelExtension.processAnnotatedType(@Observes ProcessAnnotatedType<?>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
11:39:58,254 INFO  [org.apache.camel.cdi.CdiCamelExtension] (MSC service thread 1-3) Camel CDI is starting Camel context [mycamelContext]
11:39:58,255 INFO  [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-3) Apache Camel 2.18.3 (CamelContext: mycamelContext) is starting
11:39:58,256 INFO  [] (MSC service thread 1-3) JMX is enabled
11:39:58,335 INFO  [org.apache.camel.impl.converter.DefaultTypeConverter] (MSC service thread 1-3) Loaded 189 type converters
11:39:58,351 INFO  [org.apache.camel.impl.DefaultRuntimeEndpointRegistry] (MSC service thread 1-3) Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
11:39:58,423 INFO  [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-3) StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at
11:39:58,442 INFO  [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-3) Route: route1 started and consuming from: timer://foo?period=5000
11:39:58,444 INFO  [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-3) Total 1 routes, of which 1 are started.
11:39:58,445 INFO  [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-3) Apache Camel 2.18.3 (CamelContext: mycamelContext) started in 0.189 seconds
11:39:58,557 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 60) WFLYUT0021: Registered web context: /camel-cdi-eap-1.0.0
11:39:58,578 INFO  [] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "camel-cdi-eap-1.0.0.war" (runtime-name : "camel-cdi-eap-1.0.0.war")
11:39:58,661 INFO  [] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on
11:39:58,661 INFO  [] (Controller Boot Thread) WFLYSRV0051: Admin console listening on
11:39:58,662 INFO  [] (Controller Boot Thread) WFLYSRV0025: JBoss EAP 7.0.0.GA (WildFly Core 2.1.2.Final-redhat-1) started in 4474ms - Started 360 of 649 services (382 services are lazy, passive or on-demand)
11:39:59,475 INFO  [route1] (Camel (mycamelContext) thread #0 - timer://foo) Hello Camel
11:40:04,448 INFO  [route1] (Camel (mycamelContext) thread #0 - timer://foo) Hello Camel