Sunday, February 17, 2008

Integrating WebSphere MQ 6 with BEA Weblogic Server 10 using Weblogic Server's Foreign (JMS) Server feature.

This article (in fact you may call this a set of instructions) shows you how to configure Foreign (JMS) Server in BEA WebLogic 10 Server to receive/send messages from/to queues in WebSphere MQ.

What we need:
You must have following software installed in your system:
  1. WebSphere MQ 6
  2. BEA Weblogic 10
  3. JDK 1.5 or above. (This comes bundled with Weblogic)
I assume you know compile and deploy message driven beans in Weblogic.

What we going to do:
  1. Create a queue manager and two local queues namely MQSenderQueue and MQReceiverQueue in Websphere MQ, one for sending a message to our MDB at Weblogic and other one for receiving messages from Weblogic. Create and configure JMS Foreign Server, Destinations and Connection Factories.
  2. Code and deploy a MDB in Weblogic and automatically receive messages from MQ MQSenderQueue and place it at a second MQ queue MQReceiverQueue using Weblogic Foreign JSM Server features.
For testing:
  1. Put a test message to MQSenderQueue at MQ.
  2. Monitor Weblogic console to see if it has received and sent the message again to MQ.
  3. See the message received at the MQReceiverQueue at MQ.
Creating queue managers, queues and connection factories in WebSphere MQ:

Creating queue manage
Click on Start -> Program Files -> IBM WebSphere MQ -> WebSphere MQ Explorer to open WebSphere MQ Explorer. Optionally execute C:\Program Files\ibm\WebSphere MQ\bin strmqcfg.exe to run explorer.

Image #1: WebSphere MQ Explorer

On the left hand side WebSphere MQ Explorer – Navigator pane, click on 'IBM WebSphere MQ' node to expand that, if it is not expanded already.
  • To create a queue manager, right click on the ‘Queue Managers’ node and select New -> Queue Manager.
  • In the opened window, enter name “MQTest” in the name textbox and keep clicking Next-> and finally click Finish.
Now you have created a MQ queue manager namely “MQTest”. A node “MQTest” must appear under node “Queue Managers” now as shown below:

Image #2: Create queue manager in MQ

Image #3: Create queue manager in MQ

Image #4: View queue manager in MQ

Creating WebSphere MQ local queues
Now let us create MQ queues. As I mentioned above, we are going to create two queues. We will be using one of them to put a test message which is to be received by our MDB at BEA Weblogic and the other one is used by our MDB to put message the message back into second MQ queue, so that we can see the same message again in MQ, but in the second MQ queue.

We are going to create two local queues using MQ explorer.

1. To create our first local MQ queue, right click on Queues node under “MQTest” queue manager. Select New -> Local Queue.

Image #5: Create local queue in MQ

2. Enter name for our first local MQ queue “MQSenderQueue” as shown below. Click “Next” and finally “Finish”. This is the queue we will be using to put our test message.

Image #6: Create local queue in MQ

3. Repeat the above two steps to create another local queue “MQReceiverQueue”. Note the naming I followed here – used a prefix MQ to avoid the confusions since we use similar JNDI names in Weblogic also.

Optionally, you may create MQ queue manager and local queues using command prompt. Open a command prompt (CMD) and CD to C:\Program Files\ibm\WebSphere MQ\bin.
  • Create the queue manager: crtmqm MQTest.
  • Start the queue manager: strmqm MQTest.
  • Create queues in the queue manager:
 runmqsc MQTest
Please note that I haven’t tried this option, so I am not sure how it works.

Creating JNDI Context and Connection factories
Next, create a simple file-based JNDI context and configure the JMS objects in that JNDI namespace. These JNDI objects are used by applications running in WebSphere Application Server Community Edition to connect to the WebSphere MQ queue manager. For this exercise, WebLogic and WebSphere MQ should be on the same machine.

The setting is for file-based JNDI. Create the directory C:\MQ-JNDI before continuing with the next step. Under new folder C:\MQ-JNDI, create a file with the following contents:


Next open a command prompt, cd to C:\MQ-JNDI, create the QueueConnectionFactory and Queue objects by executing the command:

“C:\Program Files\IBM\WebSphere MQ\Java\bin\JMSAdmin.bat” -cfg

You should see this prompt, where you can configure the JNDI objects:


At the prompt, copy and paste all five lines of following commands together and press Enter.

def xaqcf(MQSenderQCF) qmgr(MQTest)
def xaqcf(MQReceiverQCF) qmgr(MQTest)
def q(MQSenderQueue) qmgr(MQTest) queue(MQSenderQueue)
def q(MQReceiverQueue) qmgr(MQTest) queue(MQReceiverQueue)

You should see a message like “Stopping Websphere MQ classes for Java(tm) Message Service Administration” after you press Enter after the last line “end”.
With that, we now have MQ queues ready (see following image). Next task is to create a MDB in EJB 3 and deploy it in BEA Weblogic 10.

Image #7: MQ explorer showing queue manager and local queues.

Configuring Foreign JSM Server in BEA Weblogic Server:
Before starting your Weblogic Server you have to ensure that certain MQ related jar files are in your Weblogic Server’s classpath. Easiest way to do this is to copy following jars from “C:\Program Files\ibm\WebSphere MQ\Java\lib” folder to your Weblogic domain’s lib (C:\bea\user_projects\domains\RnD\lib in my case) folder, from where Weblogic loads them up while starting.
  3. commonservices.jar
  4. dhbcore.jar
  5. fscontext.jar
Create JMS Module
Once jars are in Weblogic Server’s class path, start your Weblogic server and login to Weblogic admin console. To start with, click ‘Lock & Edit’ button.
Expand Services -> Messaging on LHS menu and click JMS Modules link.
Click on “New” button on RHS

Image #8: Configuring JMS module

Type in a name “MQIntegrationTest” in the Name text box and press Next.

Image #9: Configuring JMS module

Select the Target server (in my case it was AdminServer) as shown below, press Next and finally Finish. Click on “Activate Changes” button on LHS.

Image #10: Creating JMS module

Create JMS Foreign Server
Click on Lock & Edit again.
Select Services -> Messaging -> JMS Modules as you did earlier, and click on newly created module
“MQIntegrationTest”. Click New button.
Select “Foreign Server” radio button and click “Next”.

Image #11: Creating JMS foreign server

Enter “MQTestForeignServer” in the Name text box, click Next button. In this page you can see that the target server is selected already. Click Finish.

Image #12: Creating JMS foreign server

Image #13: Creating JMS foreign server

Activate changes by clicking “Activate Changes” button.

Click Lock & Edit again.
Open the newly created Foreign JMS server byt clicking Services -> Messaging -> JMS Modules -> MQIntegrationTest -> MQTestForeignServer.

Under the General tab under Configuration, type in following details:

JNDI Initial Context Factory:
JNDI Connection URL:

Click “Save”.

Image #14: Configure JMS foreign server

Creating Destinations
Click on Destinations link in the Configuration tab at the top and click New

Image #15: Create Destinations

Type in following:

Local JNDI Name:
Remote JNDI Name:

Note that the Remote JNDI Name must match the name of the queue you created in WebSphere MQ broker.
Click OK.

Image #16: Configure Destination

Repeat the above to create another Destination with following details:

Local JNDI Name:
Remote JNDI Name:

Now you can see two Destinations created:

Image #17: Newly created Destinations

Creating Destinations
Let’s create two Connection Factories for above queues.
Click on Connection Factories (next to Destinations) and click New

Image #18: Create connection factories

Enter following details in “Create a New Foreign JMS Connection Factory” page.

Local JNDI Name:
Remote JNDI Name:

Again, the remote JNDI name must match on you have given to MQ connection factory.
Click Ok.

Image #19: Create connection factory

Repeat the above steps to create one more connection factory for our ReplyQueue:

Local JNDI Name:
Remote JNDI Name:

With that, you can see two Connection Factories created for our Foreign JMS Server like shown below:

Image #20: Connection factories

Click on “Activate Changes” to activate changes. With that you are done with creating and configuring Foreign JMS Server. The only thing pending before we test is to code and deploy our MDB.

Creating MDB and deploying it.
Here is the MDB code:

* File:
* Copyright (c) 2007-2008 All rights reserved.
package com.ibswings.ejb3.mdb;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.QueueConnection;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;

* Class: TestMDB
* @author Ishwara Varnasi
* @date Feb 17, 2008
@MessageDriven(name = "TestMDB", mappedName = "jms/WLReceiverQueue",
activationConfig = {@ActivationConfigProperty(
propertyName = "destinationType",
propertyValue = "javax.jms.Queue")}
public class TestMDB implements MessageListener {

public void onMessage(Message msg) {
System.out.println("=> Message received!");

if (msg instanceof TextMessage) {

try {
System.out.println("=> Message: "
+ ((TextMessage) msg).getText());
} catch (JMSException e) {

// Place the message on to the reply queue (WLReplyQueue)

@Resource(name = "WLReplyQueue", mappedName = "jms/WLReplyQueue")
private javax.jms.Queue queue;
@Resource(name = "WLReplyQCF", mappedName = "jms/WLReplyQCF")
private javax.jms.QueueConnectionFactory tcf;

public void putMessage(javax.jms.Message msg) {
System.out.println("=> Placing message on WLReplyQueue...");
QueueConnection queueConnection = null;
QueueSession queueSession = null;
QueueSender queueSender = null;

try {
queueConnection = tcf.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,
queueSender = queueSession.createSender(queue);
System.out.println("=> Message sent!");

} catch (Exception e) {
System.out.println("Exception: ");

if (e instanceof JMSException) {
((JMSException) e).getLinkedException().printStackTrace();

} finally {

try {
System.out.println("=> Closing Connection");
} catch (Exception e) {
System.out.println("Exception: ");

if (e instanceof JMSException) {
((JMSException) e).getLinkedException().printStackTrace();

public void postCreate() {
System.out.println("Bean Created");

public void preDestroy() {
System.out.println("Bean Destroyed");

The above code is for a simple message driven bean. It receives messages from MQSenderQueue and onMessage() prints out the content of text message received. Next it places the message back to the WLReplyQue. Note that in the code we never directly place message on to MQ queue. We are actually placing the message to a MQ queue namely MQReceiverQueue using Foreign JMS Server and local Weblogic JNDI name WLReplyQue.
Since we are using EJB 3, we actually do not need an ejb-jar.xml since we are using annotaions. However, to make it work on Weblogic 10, we still need a weblogic-ejb-jar.xml. Somehow I couldn’t get it working without this. Also note that I am using an older (90) schema for weblogic-ejb-jar.xml. Following is the content of Weblogic-ejb-jar.xml:

<weblogic-ejb-jar xmlns=""


Create EJB jar and deploy it in Weblogic Server. You need to restart Weblogic instance if you do any changes in MQ to reflect that in Weblogic. We are all set to test now!

Open WebSphere MQ explorer, click on MQTest (our queue manager) -> Queues. On the RHS table, right click on MQSenderQueue and select “Put test message” in the popup menu. Type in a test message, say, “Hello MQ-Weblogic World!”, click “Put Message” and close.

Image #21: Put a test message for testng.
Go to your Weblogic Servers’ output console and you will see the message. Outputs look like:

=> Message received!
=> Message: Hello MQ-Weblogic World!
=> Placing message on WLReplyQueue...

=> Message sent!
=> Closing Connection

Now go to MQ explorer and check messages in the second queue – MQReceiverQueue – you should be able to see this message.

Image #22: Queues with messages.

This article is inspired by an article by Sanjay M Kesavan at
I would like thank Mr. Kesavan, author of above wonderful article.

That’s it. You may send your feedbacks to me on


Tom Barnes said...

Thank you! Looks very helpful!

I have a few comments:

The example uses MQ "bindings" mode, which requires that MQ and WL servers all run on the same machine. To use an XA capable remote MQ client, configure the MQ connection factory with TCP mode, and use the "WebSphere MQ Extended Transactional Client" instead.

For additional JMS integration information, see FAQs: Integrating Remote JMS Providers. The FAQ explores other options and has numerous links into WebLogic documentation. For even further help, one can try posting to the

Tom Barnes, BEA Systems
WebLogic JMS Developer Team

Ishwara Varnasi said...

Hi Tom,
Thanks for your feed back and mentioning about JNDI bindings file. I missed to mention this. I will try an example with remote MQ and publish a post when I get some time.
Ishwara Varnasi

Matthew said...

Hi Ishwara,

This post has been very helpful for me. I think there's one very minor error: I think the second line of file should read:


instead of:


Thanks again,


Ishwara Varnasi said...

Matt, thanks for figuring this out. Fixed it.

ym said...

Hi Ishwara,

i have followed most of your steps.. n i have written a short test code to put message into the Queue.. but unfortunately, I kept getting this error message

java.lang.UnsatisfiedLinkError: C:\Program Files\IBM\WebSphere MQ\Java\lib\mqjbnd05.dll: Can't find dependent libraries

any idea?

ym said...

Hi Ishwara,

i have another question. let's say.. if my MQ server is not at the same server as my Weblogic server, how should i configure ? and what should i do?

Thanks in advance

Ishwara Varnasi said...

I am sorry that I am not getting time to check these things out now. Also I am working on sort of different technologies... I will try to make some time to find solutions. In the mean time, I suggest you to try finding something on related forums.

Deepu said...


I have followed all the instructions as mentioned in the post, but the message's are not being picked up by weblogic at all.

When I add a message to the SenderQueue, it just stays there, and there is no action from the MDB deployed on weblogic.

Any idea what could be wrong/missing. Thanks in advance.

Pradeep Chellur.

deepa said...

I have my MQ Server on a different machine and WLS 10 on a different machine.

Can you help me out with the changes that I need to make so that I don't get this error:
MQJMS2005: failed to create MQQueueManager for hostname:QueueManagerName


Chris said...

Would sincerely hope that you can update your guides to cater for seperate MQ and Weblogic servers setup. I am meeting the exact same issue as deepa.

Chris Chew

Ishwara Varnasi said...

Hi Chris/Deepu/Deepa...
My apologies for not having replied to your queries... Unfortunately I am not in a position to answer your questions since I have been working on technologies like SOA/ESB and Web Services for sometime now... I will try out these whenever I get some time... Tom (Tom Barnes) might be able to guide you (us) on these.
Ishwara Varnasi

Vito said...

Hi All!

Does somebody integrate MQ with Weblogic, that are located on different machines?

Please give some advise, or where can I read about it.

Thank you a lot.

Muralidhar said...


Thanks for a very helpful post.
But as many people here have asked - Any pointers on how to do it if MQ Server and WLS are on separate machines?

Thanks in advance.

best regards,

Vito said...

If you have MQ and Weblogic on separate machines, you must create binding file with connection factory, that have attribute transport=client. This means, that you are using client mode.

Than copy this binding file to machine where WLS is located, and put this location to "JNDI Connection URL" property in Foreign Server configuration.

It is the main difference.

Muralidhar said...

Hi Vito,

Thanks very much for that pointer.

I did not realize that I had to copy the bindings file to the WLS machine :) I was trying to map it thru the network.. :)

Now at least the MDB on WLS attempts to connect to MQ Server on a remote machine, though it fails.

Initially I got a ClassNotFoundException for which I had to add into WLS/domain/lib folder. That was ok.

Next, it fails with a MQ SecurityException
<28-Dec-2009 16:47:37 o'clock CET> (
at weblogic.ejb.container.internal.JMSConnectionPoller.getXAConnection(
at weblogic.ejb.container.internal.JMSConnectionPoller.getConnection(
at weblogic.ejb.container.internal.JMSConnectionPoller.createJMSConnection(
at weblogic.ejb.container.internal.JMSConnectionPoller.connect(
at weblogic.ejb.container.internal.MDConnectionManager.startConnectionPolling(
at weblogic.ejb.container.manager.MessageDrivenManager.start(
at weblogic.ejb.container.deployer.MessageDrivenBeanInfoImpl.mdManagerStart(
at weblogic.ejb.container.deployer.MessageDrivenBeanInfoImpl.deployMessageDrivenBeans(
at weblogic.ejb.container.deployer.EJBDeployer.deployMessageDrivenBeans(
at weblogic.ejb.container.deployer.EJBDeployer.deployMessageDrivenBeansUsingModuleCL(
at weblogic.ejb.container.deployer.MDBServiceImpl.startService(
at weblogic.server.ServiceActivator.start(
Caused by: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2063' ('MQRC_SECURITY_ERROR').

Possibly some MQ settings, i am still looking into it..

If someone can help ;) thanks in advance.


Muralidhar said...

Yup !!! Managed to do it !!! :)

Unfortunately it took a little time for me to get this working...but somehow managed it.

It was something to do with the configuration of Server Connection Channel in MQ Server.

On WLS startup, the MDB was not deployed properly because it was failing with MQSecurityException.

Just googled around and after a lot of trial and error, set the MCAUSER in channel to the same user who logs in. It worked. Have to read more to understand that..

Meanwhile noticed in MQ Explorer that the channel was always inactive :) and somehow missed it all the while..after setting MCAUSER, it started.

Anyways, thanks.


Anonymous said...

The WebLogic documentation links I posted above are out of date. New links:

* JMS Information Roadmap

* FAQ: Integrating Remote JMS Providers

* Using EJB/Servlet JMS Resource References
* Enhanced Support for Using WebLogic JMS with EJBs and Servlets

* Using Messaging Beans
* Programming Message-Driven Beans
* Good MDB with res-ref example (example 9-5)

Tom Barnes, Oracle
WebLogic JMS Developer Team

Anonymous said...

Thanks a lot, It is very useful.

Raghu said...

Tried searching in google, but did not find the right article. Its very useful. And that too, this is first article I read......very useful.

Thanks for your effort.

Anonymous said...

Hi Ishwara,
We've gone through your article related to Weblogic integration with Websphere MQ for Queues.
We are in the process of integrating Weblogic 10.X with Websphere MQ 6.x for Topic.
"We are getting the following error MQJMS1111: JMS1.1 The required Queues/Publish Subscribe services are not set up".

Can you please help us in resolving the error!


Anonymous said...

I tried to integrate this code for our project where MDB listens to a remote MQ server.
I faced following problems
Modify C:\Program Files\IBM\WebSphere MQ\Java\bin\JMSAdmin.bat
Modified java to %MQ_HOME%/java in order to point to corrrect location of IBM JVM.

Indranil Nag

Creation of a remote queue manager bindings by
"C:\Program Files\IBM\WebSphere MQ\Java\bin\JMSAdmin.bat" -v -cfg

use -v option for verbose output.
I tried to recreate on the existing .bindings gave lot of problem .Delete .bindings in case of error.

Enter port and server channel in case of remote mq port


def q(MQSenderQueue) qmgr(MQTest) queue(MQSenderQueue)

def q(MQReceiverQueue) qmgr(MQTest) queue(MQReceiverQueue)


For weblogic deployment copy mq jars to server lib directory otherwise you will get lots of exception for
After copying the mq jars restart the server

Indranil Nag

JONATHAN said...

When WLS and MQ are installed on different machines, we need to install MQ transactional client to successfully integrate WLS with MQ.
Install MQ transactional clinet and then run MQ's JMSAdmin utility (Step 5) to bind MQ destination with a JNDI name.

Anonymous said...

Hi sorry I'm new to weblogic. how do i create MDB and deploy it on weblogic server? is it like some other java class file?

Another question is creating EJB jar file? how do i create it?


Spenser said...

Also, One may also want to send an MQ message to remote queue from the MDB, in order to do that, old bindings file needs to be deleted and followign executed:

def xaqcf(ReceiverQCF) qmgr(testqmgr)
def xaqcf(SenderQCF) qmgr(testqmgr)
def q(MyMDBQueue) qmgr(testqmgr) queue(MyMDBQueue)
def q(MyRemoteQueue) qmgr(testqmgr) queue(MyRemoteQueue)

prior to this channels xmit queues, remote queue and local queues need to be created, also another queue manager. This can be done on the same machine, just second queue manager needs to have another port and listener port needs to change as well. Steps to create remote queues and channels can be found in tutorials of MQ explorer.

Anonymous said...

I wanna know one things. How should I add Primary /Secondary for and in the weblogic-ejb-jar.xml.


Anonymous said...

I wanna know one things. How should I add Primary /Secondary for destination-jndi and connection factory-jndi in the weblogic-ejb-jar.xml.

Anonymous said...

MDB is not able to connect destination on the Foreign JMS Server. I have the bindings file for the MQ created in file:/C:/JNDI-Directory

-----------------------------------Contents from weblogic-ejb-jar.xml



Contents from Config's descriptor file jms/mqintegrationtest-jms.xml





Any pointers on this would be appreciated

saravanavelu said...
This comment has been removed by the author.
saravanavelu said...

Hi All..

Earlier I was getting error due to JNDI look up was failed since i have targeted the Foreign server to local jms server ( used advanced targeting instead of Default targetting )

Now I managed to fix it.

But, It quite took long time.

Finally Happy..

The deployment descriptor provided by Ishwar is old and the XSI schema location is not present at all ( I guess ).. Now i have re-edited the
Deployment descriptor to deploy MDB to weblogic latest versions 10.4 etc.

if any one has doubts related to deployment descriptor.. please post.

Special Thanks to Ishwara. Move on..


srikanth said...

WebSphere MQ, a member of the WebSphere family from IBM, was the most popular system for messaging across multiple platforms.
.your providing good mater .

emily said...

your providing such a valuabe information about studying..and also have some good key points to every student.

the best pega Online Training training

subbu said...

Thx for excellent post,very useful for every one.I also follow the blog but I got one issue,i.e

cau u plz guide what I missed.


Anonymous said...

Hi All,

What is the importance of config's descriptor file while integrating weblogic and MQ on different machines? and where should i place this file? Appreciate your responses....

sri said...

When i am trying to Put a message in MQ local queue(MQSenderQueue) but, it is showing in same MQSenderQueue current queue depth.

Kaulik Shah said...
This comment has been removed by the author.
Kaulik Shah said...

Hi Guys,
I am trying to use JNDI in my Apache Camel project on spring framework. I followed exact steps & then I created JMSComponent in spring . My Application is not giving any error so Configuration seems to be correct but I am not sure what the problem is, any help is appreciated..

Here's the configuration:

(html encoded )

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="myConnectionFactory2"/>
<jee:jndi-lookup id="myConnectionFactory2" jndi-name="jms/WLReceiverQCF"/>

class HelloRoute extends RouteBuilder {
public void configure() throws Exception {

Android Training in Chennai said...

Thanks for sharing useful information about Web Logic Server and refer the link Android Training in Chennai

Android Training in Chennai said...

Thanks for sharing useful information about Web Logic Server and refer the link Android Training in Chennai