We will create a ConnectionFactory and a JMS Destination (Queue) on the Glassifsh side. Move to the GF administration console (http://localhost:4848):

Here's the ConnectionFactory:

jboss as 7 resource adapter glassfish openmq jca

and here's a Queue Destination which will be consumed by JBoss AS 7
jboss as 7 resource adapter glassfish openmq jca
So that is it: Now we need an MDB on your JBoss AS 7 instance which will consume messages from the external provider.

jboss as 7 resource adapter jca

Here's our simple MDB impementation: notice the most important part: the @ResourceAdapter definition:

package com.sample;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.jboss.ejb3.annotation.ResourceAdapter;

@MessageDriven(activationConfig = {
         
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "demoQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") 
        
})
@ResourceAdapter("imqjmsra.rar")
public class MDBSample implements MessageListener {
     
   public void onMessage(Message message) {

     TextMessage tm = (TextMessage) message;
       try {

         System.out.println("Received message "+tm.getText());

       } catch (JMSException e) {
  
        e.printStackTrace();
       }
 

   }

}

Deploy your MDB on JBoss AS 7. Now for testing it, I have created a simple JMS client, which will run on Glassfish server.

package com.sample;

import java.io.IOException;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/Test")
public class Test extends HttpServlet {
    private static final long serialVersionUID = 1L;


    @Resource(name="connFactory", mappedName="GFConnectionFactory")
    private QueueConnectionFactory qFactory;

    @Resource(name="demoQueue", mappedName="demoQueue")
    private Queue queue;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        try {
            QueueConnection qConn = (QueueConnection)qFactory.
                    createConnection();

            Session session = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer publisher;
            publisher = session.createProducer(queue);

            qConn.start();

            TextMessage message = session.createTextMessage("Received Message Hello AS 7 !");
            publisher.send(message);
        } catch (JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

It was with great satisfaction that I could read the message on the JBoss AS 7 console!!!!

jboss as 7 resource adapter jca

Download the zip folder containing the RA configuration

0
0
0
s2smodern