Integrating BEA WebLogic Server with WebSphere MQ

This article shows you how to create a default BEA WebLogic Server V8.1 SP4 instance on Windows®, connect it to IBM® WebSphere® MQ Java™ Messaging Service (JMS), and run some sample applications. For information on WebSphere MQ requirements for WebLogic, see WebSphere MQ system requirements. The article uses a sample Message Driven Bean (MDB) connecting to WebSphere MQ to receive the messages, and the same MDB forwards the received message to another queue.

Creating WebSphere MQ queue manager and configuring JMS JNDI namespace

To work with this example, you need to have a QueueConnectionFactory and Queue objects created in JNDI namespace to connect to the queue manager and access queues. Use the following commands to create a queue manager and queues in WebSphere MQ:

  1. Create the queue manager: crtmqm testqmgr.
  2. Start the queue manager: strmqm testqmgr.
  3. Create queues in the queue manager:
    runmqsc testqmgr
    	DEFINE QLOCAL("MyReplyQueue")

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:\JNDI-Directory before continuing with the next step. Create MyAdmin.config with the following contents:


Next, create the QueueConnectionFactory and Queue objects by executing the command:

C:\Program Files\IBM\WebSphere MQ\Java\bin\JMSAdmin.bat -cfg MyAdmin.config

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

At the prompt, type the following commands and press Enter after each one:

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

The above configurations are basic steps. For more information about the JMSAdmin tool, see "Chapter 5. Using the WebSphere MQ JMS administration tool" in WebSphere MQ documentation: Using Java.

Now the WebSphere MQ JMS configuration is ready for point-to-point messaging.

Creating a WebLogic server instance

Create a WebLogic server instance, then add the WebSphere MQ JMS JAR files to its classpath and do the configuration steps below:

  1. Install WebLogic Server, for example in C:\bea.
  2. Open a command window (cmd.exe).
  3. Execute C:\bea\weblogic81\server\bin\setWLSEnv.cmd.
  4. Create the server by using the wizard: Click Start => All Programs => BEA WebLogic Platform 8.1 => Configuration Wizard. Or you can use the following command:
    1. Create a directory where you want to run the test, such as C:\jms\WebLogic\test\server, and make it your current directory.
    2. Execute the following command to create the domain and server:
      java -Dweblogic.Domain=MQJMSTEST -Dweblogic.Name=MQJMSTESTSERVER
  5. After the above command has completed, stop the server, open another command window, and call C:\bea\weblogic81\server\bin\setWLSEnv.cmd by executing the following command:
    java weblogic.Admin -url t3://localhost:7001 -username weblogic 
                                           -password weblogic FORCESHUTDOWN
  6. Configure the WebLogic Server classpath to access the WebSphere MQ JMS JAR files by editing C:\jms\WebLogic\test\server\startMQJMSTEST.cmd and adding the following line just before the last command to start the server JVM:
    set MQ_JAVA=C:\Program Files\IBM\WebSphere MQ\Java\lib
        (Above line is applicable only for WebSphere MQ + Extended Transactional Client)
    set CLASSPATH=%MQ_JAVA%\fscontext.jar;%CLASSPATH%
    set PATH=%MQ_JAVA%;%PATH%
  7. Start the server by executing C:\jms\WebLogic\test\server\startMQJMSTEST.cmd.

WebLogic Server should be running. Access its admin console using http://localhost:7001/console and authenticating with user name and password (in this example we used weblogic for both).

Configuring a WebLogic foreign JMS server

Next, configure the WebLogic foreign JMS provider with the JNDI setting to access it.

Access http://localhost:7001/console, authenticating with the user name and password used in creating the WebLogic server instance above. After login, navigate to MQJMSTEST => Services => JMS => Foreign JMS Servers. In the right pane, click Configure a new Foreign JMSServer and enter the following values:

  • Name: MQJMSTEST Foreign JMS Server
  • JNDI Initial Context Factory: com.sun.jndi.fscontext.RefFSContextFactory
  • JNDI Connection URL: file:/C:/JNDI-Directory

The screen should look like this:

Figure 1. Creating new Foreign JMS Server.
Creating new Foreign JMS Server
Creating new Foreign JMS Server

Click Create at right bottom. You will get another screen to choose the instance of WebLogic Server where this foreign JMS server needs to be created. Select MQJMSTESTSERVER and click Apply.

Now you are ready to configure the QueueConnectionFactory and Queue objects in the newly created foreign JMS provider. By this step what we will be doing is that referring the QueueConnectionFactory and Queues defined in the file-based JNDI as a foreign JMS provider.

Creating QueueConnectionFactory objects in a foreign JMS provider

Navigate to MQJMSTEST => Services => JMS => Foreign JMS Servers => MQJMSTEST Foreign JMS Server => Foreign JMS Connection Factories. In the right pane, click Configure a new Foreign JMSConnection Factory and enter the following values:

  • Name: WLSenderQCF
  • Local JNDI Name: jms/WLSenderQCF
  • Remote JNDI Name: SenderQCF

The remote JNDI Name should match the QueueConnectionFactory name created in the file-based JNDI using the JMSAdmin tool. The screen should look like this:

Figure 2. Creating QueueConnectionFactory.
Creating QueueConnectionFactory
Creating QueueConnectionFactory

Click Create at right bottom to complete this operation.

Creating destination objects in the foreign JMS provider

To create the destinations, navigate to MQJMSTEST => Services => JMS => Foreign JMS Servers => MQJMSTEST Foreign JMS Server => Foreign JMS Destinations. In the right pane, click Configure a new foreign JMSDestination and enter the following values:

  • Name: WLMyReplyQueue
  • Local JNDI Name: jms/WLMyReplyQueue
  • Remote JNDI Name: MyReplyQueue

The remote JNDI Name should match the destinations created in the file-based JNDI using the JMSAdmin tool. The screen should look like this:

Figure 3. Creating Queue Destination.
Creating Queue Destination
Creating Queue Destination

Click Create at right bottom to complete the operation. Now you are ready with foreign JMS configurations to look into the MDB application.

Developing a sample application and deploying it on WebLogic

Here we use an MDB that is listening for the messages from MyMDBQueue in Queue manager testqmgr. The onMessage() picks up the messages and forwards the same message to MyReplyQueue by calling the putMessage(javax.jms.Message msg) method. The file that you can download below contains the sample application and the WLSampleMDB.ear file for deploying to WebLogic.

Extract to a directory such as C:\wlresources, and use the steps below to build an EAR file named WLSampleMDB.ear. For your convenience, an already assembled WLSampleMDB.ear file is provided in the download file.

  1. Open a command prompt and execute the following commands:
  2. cd C:\wlresources
  3. C:\bea\weblogic81\server\bin\setWLSEnv.cmd
  4. javac com\ibm\WLSampleMDB\
  5. jar -cvf WLSampleMDB.jar com META-INF (creates WLSampleMDB.jar, on which you will work further to deploy it on the server ).
  6. Start the Application Builder: Click Start => All Programs => BEA WebLogic Platform 8.1 => Other Development Tools => WebLogic Builder.
  7. In WebLogic Builder, click File =>Open and select the WLSampleMDB.jar created in Step 5 (if prompted, click Yes for creating the Deployment Descriptors).
  8. Click SampleMDBBean on the left-side tree view, select the General tab, and change the following values:
    • JNDI Name: SampleMDBBean
    • Transaction Timeout: 300
    • Destination Type: javax.jms.Queue
    • Destination JNDI: MyMDBQueue (This is the name you have given when you created a queue using JMSAdmin tool)
  9. Select the Foreign JMS Provider tab, select Use Foreign JMS Provider, and enter the following values:
    • Provider URL: file:/C:/JNDI-Directory
    • Connection Factory JNDI Name: ReceiverQCF (The Connection Factory name we created using the JMSAdmin tool for the MDB to receive the messages)
    • Initial Context Factory: com.sun.jndi.fscontext.RefFSContextFactory
  10. Select the Advanced tab and ensure that for Transaction Type, the value Container is selected.
  11. From the left-side tree view, under SampleMDBBean, select Methods and ensure that Default transaction is selected as required.
  12. From the left-side tree view, under SampleMDBBean, select Resources.
  13. Select the Resource Reference tab from the right-side pane and click Add (if the resources are already defined, click Edit). Enter the following values:
    • Resource reference Name: WLSenderQCF
    • Resource Type: javax.jms.QueueConnectionFactory
    • Resource Authority: Application
    • JNDI Name: jms/WLSenderQCF
    • Sharing Scope: Unsharable
  14. Click OK. Similarly add another resource reference with following values:
    • Resource reference Name: MyReplyQueue
    • Resource Type: javax.jms.Queue
    • Resource Authority: Application
    • JNDI Name: jms/MyReplyQueue
    • Sharing Scope: Unsharable
  15. Click File => Save to save Save WLSampleMDB.jar.
  16. To deploy this assembled JAR file, click Tools => Deploy Module. If you are asked for the configuration values to connect to WebLogic Server, verify that they match the values below:
    • Protocol: t3
    • Host: localhost
    • Port: 7001
    • Server Name: MQJMSTESTSERVER
    • System User Name: weblogic
    • System User Password: weblogic
    • Now click Connect and in next pop-up window, click Deploy Module.
  17. Test the application using the command amqsput MyMDBQueue testqmgr from the command prompt and type any text you want to put it as a message, now observe the console where the WebLogic Server is running and you should be able to see something like this:
    Message Received:
    JMS Message class: jms_text
    JMSType: null
    JMSDeliveryMode: 1
    JMSExpiration: 0
    JMSPriority: 0
    JMSMessageID: ID:414d512074657374716d6772202020203f40254420000908
    JMSTimestamp: 1143559825190
    JMSDestination: null
    JMSReplyTo: null
    JMSRedelivered: false
    JMSXAppID:WebSphere MQ\bin\amqsput.exe
    This is a Test Message
    putting the message to MyReplyQueue
    looked up QueueConnectionFactory: weblogic.deployment.jms.PooledConnectionFactory@8710bd
    looked up Queue: queue://testqmgr/MyReplyQueue
    Message send

After you press the Enter key with the blank line, you will exit from the amqsput command. For more information about amqsput, see the WebSphere MQ Documentation.


We have configured WebLogic Server and WebSphere MQ to connect to each other and used an MDB sample to get a message and forward it to another queue within a global transaction.

Downloadable resources

Related topics

ArticleTitle=Integrating BEA WebLogic Server with WebSphere MQ