Using Websphere MQ with JBoss AS 5

IBM WebSphere MQ is a family of network software products launched by IBM in March 1992. It was previously known as MQSeries, a trademark that IBM rebranded in 2002 to join the suite of WebSphere products. WebSphere MQ, which is often referred to simply as “MQ” by users, is IBM’s Message Oriented Middleware offering(JMS).

Lets see how we can configure MQ with Jboss as a pert of JMS.

Step 1: Install JBoss 5
To install JBoss AS 5, You can download it from this link

Step 2: Install Webpshere MQ 7
To install visit IBM website and download a free copy of trial.

Step3: Install wmq.jmsra.rar
The copy of wmq.jmsra.rar could be found in Inside WebSphere mq install directory e.g  wmq/java/lib/jca, Also the same can be found  if you have WAS installed. Once you got this copy put it in JBOSS_HOME/server/default/deploy

Step 4: Create wmq.jmsra-ds.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<xa-transaction />
<config-property name=”channel” type=”java.lang.String”>SYSTEM.DEF.SVRCONN</config-property>
<config-property name=”hostName” type=”java.lang.String”></config-property>
<config-property name=”port” type=”java.lang.String”>1417</config-property>
<config-property name=”queueManager” type=”java.lang.String”>JBOSS_QM</config-property>
<config-property name=”transportType” type=”java.lang.String”>CLIENT</config-property>
<mbean code=”org.jboss.resource.deployment.AdminObject” name=”jca.wmq:name=ivtqueue”>
<!– Bind this AdminObject with the JNDI name IVTQueue –>
<attribute name=”JNDIName”>IVTQueue</attribute>
<depends optional-attribute-name=”RARName”>jboss.jca:service=RARDeployment,name=’wmq.jmsra.rar'</depends>
<attribute name=”Type”>javax.jms.Queue</attribute>
<attribute name=”Properties”>

Step 5:  Create a EJB 3.0 project in JBoss Studio or in Eclipse IDE.

Step 6: Write a Message Driven Bean



import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.jboss.ejb3.annotation.ResourceAdapter;

* Message-Driven Bean implementation class for: MQJbossExample

@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = “destinationType”,
propertyValue = “javax.jms.Queue”),

@ActivationConfigProperty(propertyName = “messagingType”,
propertyValue = “javax.jms.MessageListener”),

@ActivationConfigProperty(propertyName = “destination”, propertyValue = “JBOSS_Q”),

@ActivationConfigProperty(propertyName = “queueManager”, propertyValue = “JBOSS_QM”),
@ActivationConfigProperty(propertyName = “hostName”, propertyValue = “”),
@ActivationConfigProperty(propertyName = “port”, propertyValue = “1417”),
@ActivationConfigProperty(propertyName = “channel”, propertyValue = “SYSTEM.DEF.SVRCONN”),

@ActivationConfigProperty(propertyName = “transportType”,propertyValue = “CLIENT”), },

messageListenerInterface = MessageListener.class)


public class MQJbossExample implements MessageListener, MessageDrivenBean {

private int maxMessageLength = 50820;

private BytesMessage byteMessage = null;

private static final long serialVersionUID = 1L;

String recievedMessageFromWSMq = “”;

* Default constructor.
public MQJbossExample() {
// TODO Auto-generated constructor stub

* @see MessageDrivenBean#ejbRemove()
public void ejbRemove() {
// TODO Auto-generated method stub

* @see MessageDrivenBean#setMessageDrivenContext(MessageDrivenContext)
public void setMessageDrivenContext(MessageDrivenContext arg0) {
// TODO Auto-generated method stub

* @see MessageListener#onMessage(Message)
public void onMessage(Message message) {
// TODO Auto-generated method stub
try {

if (message != null) {

if (message instanceof TextMessage) {

recievedMessageFromWSMq = ((TextMessage) message).getText();
System.out.println(” recievedMessageFromWSMq ”
+ recievedMessageFromWSMq);

} else if (message instanceof BytesMessage) {

byteMessage = (BytesMessage) message;

byte[] buffer = new byte[maxMessageLength];

int byteRead;

ByteArrayOutputStream bOut = new ByteArrayOutputStream();

while ((byteRead = byteMessage.readBytes(buffer)) != -1) {

bOut.write(buffer, 0, byteRead);


try {


recievedMessageFromWSMq = new String(bOut.toByteArray());
System.out.println(” recievedMessageFromWSMq ”
+ recievedMessageFromWSMq);


} catch (Exception e) {





} catch (JMSException e1) {




Step 7:  Now Build the project.Start the server, If all the configuration are correct then you will see binding information of the JNDI name in the server logs, This is the first indication that Link between MQ and JBoss has successfully created.

21:13:29,812 INFO [ConnectionFactoryBindingService] Bound ConnectionManager ‘jboss.jca:service=ConnectionFactoryBinding,name=JmsXA’ to JNDI name ‘java:JmsXA’
21:13:29,984 INFO [AdminObject] Bound admin object ‘’ at ‘IVTQueue’

Step 8:  Now deploy the application on Jboss.

21:15:42,515 INFO  [EJBContainer] STARTED EJB: ejbName: MQJbossExample

Step 9: Now Open Websphere MQ Explorer and put a message on the Queue.

Step 10: Once you put a dummy message on the Queue, See in the server logs to observe the message recived by our Message Driven bean.

See how simple it is to integrate Jboss with MQ. Hope this helps 🙂

R Vashi

5 thoughts on “Using Websphere MQ with JBoss AS 5

  1. Andy Piper

    Nice write up – just to note that the most recent version of WMQ is 7.1 which has significant performance benefits both in the UI and in the runtime. You should definitely check it out! 🙂

  2. babu

    Hi I am using the same configuration like JAva 6 +Spring JMS JBoss 5 + Ibm MQ 7.
    I am trying to replace WEblogic Queue with IBM MQ. Please help me to configure IBM MQ calls in Spring.xml file. Now i am using file with (weblogic.provider.url=t3:// and weblogic.provider.jndi.queuename=jms.My-Queue) and in Spring.xml calling properties file
    Using :



    2. I need to configure IBM MQ in Spring.xml .

    Please help me . Thanks for advance

  3. Marty

    I’ve had to build almost exactly the same configuration using Spring. This was a great help verifying what that my approach has been correct. One question though, how does one format the jndi-name when doing a jndi-lookup for the bean:


    I’m getting a jboss error that starts off as follows:
    Cannot resolve reference to bean ‘nfnJSMSMSConsumerConnectionFactory’ while setting bean property ‘connectionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException:

    Thanks in advance..


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.