Tuesday, October 21, 2008

Integrating Apache Camel with JBoss ESB

Motivation

JBoss ESB supports the EIP(Enterprise Integration Patterns) in many aspects and counting with sofisticated resources, for instance: Drools for CBR(Content Based Router), or jBPM for Business Processor, besides of components for implementing Splitters, Aggregators, Filters and so on. However, not only to prove that JBoss ESB is an open and flexible ESB, I decided integrate it with Apache Camel, and this entry will show you some aspects of this work.

Little About Apache Camel

From Camel website (http://activemq.apache.org/camel/)

"Apache Camel is a Spring based Integration Framework which implements the Enterprise Integration Patterns with powerful Bean Integration.

Camel lets you create the Enterprise Integration Patterns to implement routing and mediation rules in either a Java based Domain Specific Language (or Fluent API), via Spring based Xml Configuration files or via the Scala DSL. This means you get smart completion of routing rules in your IDE whether in your Java, Scala or XML editor.

Apache Camel uses URIs so that it can easily work directly with any kind of Transport or messaging model such as HTTP, ActiveMQ, JMS, JBI, SCA, MINA or CXF Bus API together with working with pluggable Data Format options. Apache Camel is a small library which has minimal dependencies for easy embedding in any Java application."

In addition to this, Camel has several components that allows us apply an "Event-Driven" approach, the list of providers or protocols is really interesting, that's why Camel called my atention some months back, and working with a SOA project, where one of the requirements is listen many "non-common" protocols! So I believe that Camel can help me to avoid reinvent de wheel. Moreover, you can ask me: "Hey sir, tell me some about you bunch of components that you can use on Camel?", and I can answer with the following:
  • Apache Mina
  • RelaxNG
  • XMPP
  • Microsoft MQ
  • JCR
  • JBI
  • IRC
  • HL7
  • ESPER(CEP/ESP)
  • ATOM
  • Others , see more here

A Real Use Case: Turning On Camel into JBoss ESB

Depending of the point of view, you can definetely think that it is crappy, although I personally believe that Camel can work with JBoss ESB, once you have many events(Messages) happening on that protocols mapped by Camel's componets, you can eventually catch one of these messages(events) via Apache Camel, where we consider an "Unaware ESB Message from an Unaware Client" and publish it into a provider(protocol) that JBoss ESB supports, such as JMS, File System, WebServices, JBoss Remoting an so on. See the following image where I try describe visually this bahaviour:


In my case, I wanna listen everything what happens into a UDP server connection, and due to performance I would like to use something on top of NIO: So Apache Mina is one of my options, I could create a new JBoss ESB Courier(provider), new ProviderListener and everything from scratch, but I decided test Apache Camel, and my experience is that it was incredible cool,easy and under my performance testing really interesting, comparing with the previous UDP Server made using basic Java IO implementation.

First of all, I used the JBoss ESB's internal scheduler infrastructure, I enabled a SchedulerProvider to start my "Camel Listener", on this point I just wanna enable the Apache Camel run into ESB(inESB). See in the following code the provider configuration:


After this I created a listener for my service, just to tell which "Timer Event Listener" I wanna invoke when my CRON expression had been executed. In the following code, you can see my ESB Timer listener activating my UDP component listener based in Camel:

The class you can see in my listener is basically the timer listener processor that will be fired when the cron expression happens. In that case I am implementing the JBoss ESB's interface: org.jboss.soa.esb.schedule.ScheduledEventListener, especifically the method onSchedule(), which is fired my my listener according the CRON expression in my scheduler provider. In particular, on that method I invoke the Camel capabilities, as you can see in the following code:

The Camel portion is really easy to understand: This frameworks works with URI concept, so the compoenents "endpoints" no matter for input or output are configured using those URI and a Java DSL for it, in the example you can see above, We hve a method process which is resposible for handling the message/information that arrives in the configured component(endpoint), in that case I am telling that this method will listen eveything that happens in a UDP server in my host 0.0.0.0 in the port 2222, so the message that I receive I can do everything I want with, and after I route this information for another component, in that case we are forwarding the message to a filesystem, in that case a Filesystem can be a gateway for JBoss ESB, but we could route the info for a JMS or HTTP(JBR) gateway as well.

I believe I can improve a lot the integration between JBoss ESB and Camel, there are some issues, like redeployments in ESB and CamelContexts stoping and restarting that I can synchronize, but for awhile it is working pretty well.

I hope this post can be useful for you, if you need any further information please comment here.

More info:

http://www.jboss.org/jbossesb

http://activemq.apache.org/camel/

http://mina.apache.org/

Tuesday, October 14, 2008

Getting Started with JBoss ESB 4.4 and JBoss Tools 3-beta - Part I

Introduction

This entry introduce you how create ESB Projects using JBoss ESB with Eclipse IDE.

Softwares Used for this Tutorial

  • JBoss ESB Server 4.4
  • Eclipse Ganymed (latest version is ok)
  • Nightlly build (JBossTools-3.0.0.Beta1) for example: JBossTools-3.0.0.Beta1-N200810131557
  • JDK for sure :)
Installing the Software

In Eclipse Ganymed you have a way to avoid mess your Eclipse installation, you may use the dropins folder to make the reference between your original Eclipse installation and the folder were you had unziped your plugin and where the contents are located in. See the following links for more detailed information in how get it ready :

Configuring JBoss ESB in Eclipse

Once you have the installation process done, go to the Window/Prefereces, and expand the item JBoss Tools on the left, you will see the JBoss ESB Runtimes as one of the items in this section, click on it and in the right window click in the add button and select the JBoss ESB Server path. See the Image 1: and 2:

Image 1 - The Preferences Window
Image 2 - The JBoss ESBConfiguration
Creating a New Project

Now, go to the file/new/other ... And Select ESB/ESB Project, as you can see in the image 3, select this item and press Next Button:

Image 3 - Creating a new ESB Project

Fill "MyFirstEclipseESBProject" in the "Project Name" field and click on the "Finish" button.

After this, the Project is created and you will be ready to develop your services based on JBoss ESB. See the last image of this post:














Tuesday, October 7, 2008

esbgen: An easy way to create JBoss ESB Projects

The esbgen.sh or .bat is a simple command line tool that can help you create or just setup your first JBoss ESB Project.
If you think it could be interesting (for sure it is ;]), you can download the zip from esbgen from this JIRA ISSUE: https://jira.jboss.org/jira/browse/JBESB-2098, please VOTE there :)

In JIRA, you can find out the instructions, and here you can see esbgen in action on the screencast.

Hope you enjoy it!