Skip to main content

Red Hat JBoss Fuse - 3 ways to develop you Fuse application in JBoss EAP, Java DSL

In this series post I am going to show the different ways of developing a Camel web application running in JBoss EAP.
  • Spring Framework
  • CDI with Java DSL
  • XML without Spring
To make things clear and easy, I will be using the exact same Camel route for all there different methods.What this Camel route does, is it starts up a timer that will log every 5 second, simple, easy, not much going on.

Before we start develop our simple camel route, we need to a base WAR project to work on, so first we need to create a WAR file, I am sure you must have a million way to create that, every one sort of have their own best practice for this. For me, in the example, I will create one with maven, using the webapp-javaee6 artifact. 

A. Create Project, select Maven Project, 

B. Click Next when you are at New Maven Project, and it will take you to the next step, select the webapp-javaee6 artifact.

C. Add your project name, and then click Next, you will have a ready to go WAR project in your JBoss Developer Studio. (Note, for my examples later, I am going to give them different project Names)

D. Add Camel dependency in the pom.xml file (do make sure you maven repo is configure properly pointing to http://repo.fusesource.com/nexus/content/repositories/releases)

    <!-- camel -->
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>2.15.1.redhat-621xxx</version>
      <scope>provided</scope>
    </dependency>


E. Optional, change your JDK version accordingly in pom.xml of the WAR project.




Java DSL

The major difference between Karaf and JBoss EAP is that JBoss EAP supports JavaEE specification. From JavaEE 6, it introduces a new framework, Contexts and Dependency Injection, similar to what Spring has done, allows users to defines a type-safe Dependency Injection as well as provide a well managed "contextual" references lifecycle for Java beans. In many case, we want to take advantage of this standard and let it manages our Bean in Camel. To lookup these beans in Camel route, we need to use the Java DSL.  

  • Before we start, we are going to need another camel dependency, 


        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cdi</artifactId>
            <version>2.15.1.redhat-620133</version>
            <scope>provided</scope>
        </dependency>
  • Enable CDI in your web application by placing an empty beans.xml under WEB-INF in webapp folder. Create folder WEB-INF , and XML file beans.xml
       

  •  This is what your beans.xml should look like

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       bean-discovery-mode="all">
</beans>
  • Now I am going to show you how to create one, create a Java Class that extends org.apache.camel.builder.RouteBuilder, called MyCamelRouteBuilder.java



  • Inside the method , add the following Camel Route, 

    from("timer:mytimer?period=5000")
    .log("Java DSL Camel Demo");

  • Add your camel route to the Application Scope, Register it's context and starts up by setting the following annotation on top of your class.
    • @Startup
    • @ApplicationScoped
    • @ContextName("cdi-context")

  • Your Java Class will look like this

package com.redhat.mycdidemo;

import org.apache.camel.builder.RouteBuilder;

@Startup
@ApplicationScoped
@ContextName("cdi-context")
public class MyCamelRouteBuilder extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("timer:mytimer?period=5000")
    .log("Java DSL Camel Demo");
  }
}

  • And then we are done, ready to go. Run mvn clean install to generate the war file. 





  • Start up your JBoss EAP with Fuse subsystem enabled. If you are not sure how to do it, please take a look at this post. In side bin folder, start JBoss EAP with 
    • standalone.sh
    • standalone.bat
  • Go to http://localhost:9990/, login to admin console, under Runtime/


  • Click on Add, choose the war generated under the project target folder. Click Next, Next to deploy the application. 
  • Start up application by click on the En/Disable button. 

  • Switch to the log, you will find it's now printing the message "Java DSL Camel Demo" every 5 seconds.



Comments

Popular posts from this blog

Fuse Integration Service - Setup JBDS and create first quickstart application

Before we go and start creating our first application, I want to show you how to setup your JBoss Developer Studio, create a small application from the quickstart example and then running it on Fuse Integration Service.

I am using JBoss Developer Studio version 9, you can find it here.
After download the

jboss-devstudio-9.0.0.GA-installer-eap.jar
double-click it, and start installing with default values.

After successful installation, we will need install the plugins for Fuse, on JBoss Central view, select software update, select enable early access.


And select JBoss Fuse Development for the plugin,


Click on install, and we are all set to go!

First thing first, we want to create a Fuse project to deploy on the base of Fuse Integration Service, which is OpenShift. If you have not installed it, please go back to my previous post for instructions. So on your JBDS, right click and start creating the project. Select new, maven project, if you have installed the plugin correctly, you should …

RHTE - Supercharge your integration services

Red Hat Tech Exchange has taken place in Vietnam, Ho Chi Minh city two weeks ago, it is a great event held by Red Hat in Asia Pacific Region. It is open to all Red Hat partners who are interested in learning what Red Hat is doing recently, see what the trend of the open source world, basically it is a great event to share your knowledge and experience, to meet other enthusiastic people.

I am very fortunate to talk in this great event, to talk about the things I have been working on and even discuss it with many. Also got lots of great ideas too. So here are the slide.

My first talk was with Thomas Qvarnström about how to handle large size data in JBoss Fuse and how JBoss Data Grid can help in the situation.

Here is the agenda of the talk, we will be talk about this in the up coming webinar on 24th Sept.

Integration often involves storing, retrieving, and transforming data. Using a traditional database in your integration is likely to becomes a bottleneck that is expensive and hard to …

Red Hat JBoss Fuse/A-MQ - Fuse and A-MQ Version 6.3 GA is released!

Fuse and A-MQ 6.3 GA has just went out. Maybe, you would think this is just only a minor version release why should I care? Hold your thoughts on that! Because they have done a lot of improvements and also added many new features into this release.

Besides various bug fixes and making sure Fuse Fabric is much more stable. There are two major change in this version update:

New Tooling in JBoss Developer Studio (JBDS) 9.1 GA. Newer Apache Camel version – Camel v2.17. I was really impressed by the work put in to make developing Camel application much simpler. First is the installation of tooling itself. Now it has a all-in-one installer so you don't need to worry about which plugins you need to check. See the videos below to see the new "Getting Started" of Fuse 6.3.



And If you notice from the above video, the presentation of camel route in JBDS has also updated. It fixed some of the miss representation of logic and making it easier to read.

Old Camel Route
New Camel Route
On …