Getting Started with JBoss ESB

By Farhana Shaikh

Getting Started with JBoss ESB What is an ESB ?

Enterprise Service Bus is an application that gives access to other applications. Main task of ESB is messaging and integration backbone. All the services are connected to Enterprise Service Bus.

Services are connected to Enterprise Service Bus

In ESB clients and services communicate via ESB. They do not communicate directly.

JBoss ESB

JBoss ESB is an open source Enterprise Service Bus. JBoss ESB provides many facilities like integrate new and legacy systems also handle the routing and services. JBoss ESB architecture is based on SOA principles in which loose-coupling, message passing approaches are used.

JBoss ESB Service B (destination)

Client Service A Router Service C (destination)

Getting Started with JBoss ESB Download JBoss ESB

We can download JBoss ESB from http://jbossesb.jboss.org/downloads page. Currently new version of JBoss ESB is 4.12.

There are three packages jbossesb-4.12-src.zip, jbossesb-server-4.12.zip, and jbossesb-4.12.zip. jbossesb-4.12-src.zip: Contains the source code for JBoss ESB. jbossesb-server-4.12.zip: jbossesb-server is pre-configured Application server. Basically this server is configured with version 4.2 of JBoss Application server jbossesb-4.12.zip: This is standalone binary distribution

Installing JBoss Developer Studio

JBoss Developer Studio is an based IDE. This is fully integrated with JBoss Application Server

Download latest version of JBDS on https://www.jboss.org/products/devstudio/overview/ page Download version 5 of JBoss Developer Studio from below url http://wiki.openkm.com/index.php/Download_JBoss_Developer_Studio OR https://devstudio.jboss.com/earlyaccess/5.0.0.GA.html

Getting Started with JBoss ESB How to Install JBoss Developer Studio

Run installer by following command java -jar jbdevstudio-product-universal-5.0.0.v20120615-1714-H213-GA.jar

There are total 9 steps to install JBDS

First step is Introduction

Getting Started with JBoss ESB Second step is End User License Agreement

Step 3 is choose installation directory

Getting Started with JBoss ESB Step 4 is Select Java JVM

Step 5 is Select Platforms and Servers

Getting Started with JBoss ESB Select Add and Browse the server.

Step 6 is Summary information verify name and location and click next

Getting Started with JBoss ESB Step 7 is Installation. It supplied all the information to the JBoss ESB installer

After compliting the installation next step is to Setup shortcuts

Getting Started with JBoss ESB Now, we can see the following screen. Successfully complition of setup. Installation has completed successfully

Click on Done to close the installer Now goto the installation path run jbdevstudio. We can see Welcome Screen

Getting Started with JBoss ESB Now, We have to install jboss esb plugins in JBoss Studio. Go to Help menu. Select Install new software. Enter https://devstudio.jboss.com/updates/5.0/soa-tooling/

Getting Started with JBoss ESB Select JBoss ESB tools and install JBoss ESB plugins. After installing the plugins it will ask for restart. Then Restart the JBoss studio and set up the prefrences for JBoss ESB Go to Window select prefrences | Jboss Tools -> JBoss ESB Runtimes. Then Add jbossesb runtime.

After defining the JBoss ESB Runtimes now time to start the JBoss AS server.

How to start JBoss AS Server

Select Window -> Show View-> Other-> Server and then click ok. Server dialog will be displayed.

Now, click on Server wizard. Select from JBoss Community JBoss AS 4.2 and assign JBoss Application server. Here we are using jbossesb-server-4.11

Getting Started with JBoss ESB .

Getting Started with JBoss ESB Now, Right click on Server and click on start. Then console log will open automatically. Now make sure whether Application server started successfully or not. Select Window-> Show View->Other-> General-> Internal Web Browser Now, Enter http://localhost:8080/ and we will see the following window.

Finally, JBoss Developer Studio configured with JBoss AS server.

Now, we will see one simple example for simple printing message. Click on New-> Project-> ESB Project

Getting Started with JBoss ESB Give unique Project name, select appropriate version then click on next

Getting Started with JBoss ESB Click on Finish, we can see our project structure as below

Getting Started with JBoss ESB jboss-esb.: It contains the service configuration such as listeners, actions, provider, as well as services configuration. deployment.xml: We specify classloading order in deployment.xml file. Deployment.xml file is optional but whenever we make the deployment of .esb archive scoped at that time we have to create this file jbm-queue-service.xml: If provider of jboss-esb.xml references any queue we can deploy their configuration in the ESB archive. Example: First we create JMS Provider in jboss-esb.xml file.

Both properties name and connection-factory are required. Click on next and give busid.

Getting Started with JBoss ESB Click on Finish, By this way create two channels GWChannel and ESBChannel. Code is define as below.

Now, create services. A Service can define list of Action and list of listeners. A list of Action classes which process an ESB messages in sequential manner. A list of listeners which act as router. They route the messages to the Action Pipeline.

Getting Started with JBoss ESB

In Service category, name and description attributes are required. All these attributes are used to register the Service endpoints in the Service Registry. In this example we used two listeners. Gateway Listeners and ESB-Aware Listeners.

Gateway Listeners: Endpoint of Gateway Listener is used to get messages onto an ESB bus. This listeners is responsible for normalizing the message payload. ESB-Aware Listeners: Endpoint of ESB-Aware listener is used to exchange ESB messages between ESB component.

Getting Started with JBoss ESB How to Deploy Application

Right click on server click on Add and Remove then select the application we want to deploy. Click on Add button. Then click on Finish

Now, server will be started and ESB file will be deployed to the server. Run our class SendJMSMessageDemo.java. Output should be

Getting Started with JBoss ESB Message Body

Message Body contains main payload informaion. The Payload should consists of data which is required by service contract. The body consists of Main payload and Named Objects.

Main Payload can access using following methods: public Object get() public void add(final Object value)

Named objects can access using following methods: public Object get(final String name) public void add(final String name,final Object value)

Custom Action Class

Now, We will create custom Action class that print the message Body. Right click on our package create new class MyActionDemo import org.jboss.soa.esb.actions.AbstractActionLifecycle; import org.jboss.soa.esb.helpers.ConfigTree; import org.jboss.soa.esb.message.Message; public class MyActionDemo extends AbstractActionLifecycle {

protected ConfigTree _config; public MyActionDemo(ConfigTree config) { _config=config; } public Message displayMessage(Message msg)throws Exception {

System.out.println("**************************************************"); System.out.println("Message Body-> " + msg.getBody().get()); System.out.println("**************************************************"); return msg; } }

After creating java class next step is create custom Action in jboss-esb.xml

Click Save and deploy the application. Once application is deployed then run our class SendJMSMessageDemo.java.

Getting Started with JBoss ESB The Output in console

Here, we create our own custom action class. This class used the MessageAPI to get the main payload of message and that message is displayed in console

ServiceInvoker

Each service associated with one or more ESB Aware Listeners, and physical endpoints. An ESB Aware Listener receives a message and pass it through service pipeline for execution. Org.jboss.soa.esb.client.ServiceInvoker utilit class is used for communicating with the physical endpoints. The service consumer handle the ceation of message and decide whether the invocation should required response or not.

Synchronous delivery

In synchronous delivery service consumer waits for the response final ServiceInvoker service_invoker=new ServiceInvoker(category, name); final Message msg_response=service_invoker.deliverSync(request,timeout);

Getting Started with JBoss ESB The service consumer invokes the deliverySync method for synchronous delivery. In deliverySync method timeout parameter specify how long it is prepared to wait for a response.

Asynchronous delivery

In Asynchronous delivery the service consumer does not wait for the response. final ServiceInvoker service_invoker=new ServiceInvoker(category, name); service_invoker.deliverAsync(request);

In Asynchronous delivery result is more robust compare with synchronous delivery.

Now Let us see example.

Right click in our package create new class SendEsbMessage public class SendEsbMessage { public static void main(String args[]) throws Exception {

System.setProperty("javax.xml.registry.ConnectionFactoryClass","org.apache.ws.scout.registry.Con nectionFactoryImpl");

if (args.length < 3) { System.out.println("Usage of SendEsbMessage category ,name, text to send"); args = new String[]{"SampleCategory", "SampleService", "say hello esb invoked"}; }

Message esbMessage = MessageFactory.getInstance().getMessage();

esbMessage.getBody().add(args[2]);

new ServiceInvoker(args[0], args[1]).deliverAsync(esbMessage);

}

}

Now, deploy the application and run SendEsbMessage.java file. The Output in console..

12:03:55,150 INFO [STDOUT] ************************************************** 12:03:55,151 INFO [STDOUT] Message Body say hello esb invoked

Getting Started with JBoss ESB 12:03:55,151 INFO [STDOUT] **************************************************

The ServiceInvoker uses the jbossesb-properties file that is under the root of our project. Jbossesb- properties.xml file contains all the configuration for the ServiceInvoker to read.

Common Errors facing in JBoss ESB

Class not found exception This exception occurred whenever .jar file is missing. If CLASSPATH environment is not set correctly Java not found exception This exception occurred whenever PATH environment variable is not set correctly Address already in use exception This exception occurred whenever server is already running on the port that the server we are starting is trying to use. By default JBoss AS runs on port 8080 Illegal state exception If there is some error in jboss-esb.xml file at that time this exception is occurred. Invalid configuration file

Getting Started with JBoss ESB