JBoss ESB tutorial

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

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.

The deployed archive will be packaged with the .esb extension and contains the same structure you can see in your  "esbcontent" branch , plus the Java classes. Here's an example of .esb project file:

jboss esb

Creating a Test Client

As 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:

  • sending an ESB aware message to the queue queue/eclipse_quickstart_helloworld_Request_esb. 
  • sending a plain JMS message to the queue queue/quickstart_helloworld_Request_gw. 


For the purpose of this tutorial we'll see how to connect with a simple JMS message (the ESB aware message can be found in the same folder of the HelloWorld sample) :

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:

jboss esb

 In step 1, the JMS client send a raw JMS message to the queue "queue/eclipse_quickstart_helloworld_Request_gw".

The JMS listener receives the raw JMS message (step 2) and adapts the message to the ESB aware message format, but before doing this, it needs to know the endpoint of the Service. So the JMS listener first contact (step 3) the Service Registry  (that keeps track of all Service Endpoints References), then normalize the message and place in the the JMS queue "queue/eclipse_quickstart_helloworld_Request_esb"  (step 4)

When the message is placed in this queue the Service "MyJMSListenerAction" is triggered and the content of the Message is extracted and passed to the displayMessage (see step 5).

If all steps performed are successfull you should see a dump on the Server Console of the JMS message sent to the Queue.

That's all! 

Enjoy JBoss ESB !

Follow us on Twitter