| JBoss ESB with JBoss Tools plugin |
| Written by F.Marchioni | |||||
|
This tutorial is a rewritten version of JBoss ESB tutorial: a new stable version of JBoss Tools has been released with the ESB plugin so we'll use it to set up a JBoss ESB project. A Bit of theory first To get a manageable SOA, you’ll need to start with SOA platforms that represent a relatively low investment. That’ll likely mean tools and platforms that are open source, with support and ecosystem benefits available at a low cost. JBoss team have designed their own Service Bus: JBoss Enterprise Service Bus is a robust SOA solution designed since the release 4.2 with build-in fail-over, load balancing and delayed message redelivery. JBossESB allows you to distribute service instances across many nodes. Each node can be a virtual or physical machine running one or more instances of JBossESB. How the physical implementation of the architecture is achieved -however- is not fundamental: in fact many different implementations and sub-architectures could be used. So what is the fundamental concept or idea in which to work when considering SOA? The fundamental of SOA is a unitary event bus which is triggered by receipt of a Message: a service registers with this bus to be informed when messages arrive. Next up the chain is a handler (dispatcher), that allows for sub-services (sub-components) to register for sub-documents (sub-messages) that may be logically or physically embedded in the initially received message. This is an entirely recursive architecture.
As such, JBossESB uses a message driven pattern for service definitions and structures: clients send Messages to services and the basic service interface is essentially a single doSomething method that operates on the Message received. Internally a service is structured from one or more Actions, that can be chained together to process incoming the incoming Message. What an Action does is implementation dependent, e.g., update a database table entry, or call an EJB. So when developing your services, you first need to determine the conceptual interface/contract that it exposes to users/consumers. This contract should be defined in terms of Messages, e.g., what the payload looks like, what type of response Message will be generated (if any) etc. How is made up a Service in JBoss ESB? A service in JBossESB is defined a list of Action classes that process an ESB Message in a sequential manner. This list of Action classes is referred to as an Action Pipeline. A Service can define a list of Listeners, which act as inbound routers for the Service, routing messages to the Action Pipeline. JBossESB supports two forms of listener configuration: Step 1 : Download the ESBOk, now let's get our hands dirty: at first download the latest ESB from jboss site: Step 2: Install JBoss ESB plugin on EclipseFor our example we have installed Eclipse IDE for Java Developers (Ganymede) which is the Enterprise Version of Eclipse foundation: check it here: If everything was correctly installed you should see from the Menu the Option "New-->ESB-->ESB Project". Step 4: Design your ESB projectAt the beginning you have an empty project with "esbcontent" folder where you store your project configuration. The main configuration file of JBoss ESB is jboss-esb.xml. A blank version is provided under META-INF.
;?xml version = "1.0" encoding = "UTF-8"?>
<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5">
<providers>
<jms-provider name="JBossMQ" connection-factory="ConnectionFactory">
<jms-bus busid="quickstartGwChannel">
<jms-message-filter
dest-type="QUEUE"
dest-name="queue/quickstart_helloworld_Request_gw"
/>
</jms-bus>
<jms-bus busid="quickstartEsbChannel">
<jms-message-filter
dest-type="QUEUE"
dest-name="queue/quickstart_helloworld_Request_esb"
/>
</jms-bus>
</jms-provider>
</providers>
<services>
<service
category="FirstServiceESB"
name="SimpleListener"
description="Hello World">
<listeners>
<jms-listener name="JMS-Gateway"
busidref="quickstartGwChannel"
is-gateway="true"
/>
<jms-listener name="helloWorld"
busidref="quickstartEsbChannel"
/>
</listeners>
<actions mep="OneWay">
<action name="action1"
class="org.jboss.soa.esb.samples.quickstart.helloworld.MyJMSListenerAction"
process="displayMessage"
/>
</service>
</services>
</jbossesb>
The second section describes the service itself and the listeners : as you can see there are As said before the JMS gateway listener is responsible for carrying the message to the ESB (adapting them to the ESB "style") while the ESB Aware listener is used to exchange message to ESB aware components.
package org.jboss.soa.esb.samples.quickstart.helloworld;
import org.jboss.soa.esb.actions.AbstractActionLifecycle;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
public class MyJMSListenerAction extends AbstractActionLifecycle
{
protected ConfigTree _config;
public MyJMSListenerAction(ConfigTree config) {
_config = config;
}
public Message displayMessage(Message message) throws Exception{
System.out.println("Body: " +message.getBody().get());
return message;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server>
Finally we need a file which specifies the resources this esb archive depends on : this file is deployment.xml and needs to be placed into the META-INF folder: <jbossesb-deployment> <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb</depends> <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw</depends> </jbossesb-deployment> Ok. now your ESB project is ready to rumble! Check that your project looks like this in your Project Explored window: ![]() Deploy your project: In order to deploy your project to the Service Bus all you have to do is Right-Click on your server window and choose "Add-Remove Project". Add your project to the list of deployments. Now everytime you change your project, just take care to "Republish" it, again from the server window. ![]() Creating a Test ClientAs you can see from your configuration file, you have two active channels which are active on your Service Bus, so you can receive Messages in two ways:
package org.jboss.soa.esb.samples.quickstart.helloworld.test;
import java.util.Properties;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class SendJMSMessage {
QueueConnection conn;
QueueSession session;
Queue que;
public void setupConnection() throws JMSException, NamingException
{
Properties properties1 = new Properties();
properties1.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties1.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext iniCtx = new InitialContext(properties1);
Object tmp = iniCtx.lookup("ConnectionFactory");
QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
conn = qcf.createQueueConnection();
que = (Queue) iniCtx.lookup("queue/quickstart_helloworld_Request_gw");
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
System.out.println("Connection Started");
}
public void stop() throws JMSException
{
conn.stop();
session.close();
conn.close();
}
public void sendAMessage(String msg) throws JMSException {
QueueSender send = session.createSender(que);
ObjectMessage tm = session.createObjectMessage(msg);
send.send(tm);
send.close();
}
public static void main(String args[]) throws Exception
{
SendJMSMessage sm = new SendJMSMessage();
sm.setupConnection();
sm.sendAMessage(args[0]);
sm.stop();
}
}
As you can see from the picture below, sending a JMS message causes the interaction between the two listeners:
In step 1, the JMS client send a raw JMS message to the queue "queue/eclipse_quickstart_helloworld_Request_gw". If all steps performed are successfull you should see a dump on the Server Console of the JMS message sent to the Queue. Enjoy JBoss ESB !
JBoss.org Search
Custom Search
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |









