How to Configure WebLogic Server with IBM WebSphere MQ V6 or V7 as a Foreign JMS Server in Two Different Machines

WebSphere MQ Information Center
WebSphere MQ Information Center (Photo credit: peter_anghelides)


Configuring WebSphere MQ

Please follow these steps:

  1. In the WebSphere MQ Explorer Navigator pane, click on the 'IBM WebSphere MQ' node to expand it.
  2. Create a queue manager by right clicking on the Queue Manager node and selecting New -> Queue Manager.
  3. In the opened window, enter the name MQTest in the Name text box. Ensure that you choose a port which is not already in use. Otherwise, accept the default options by clicking Next until you reach 'Finish' and finally click Finish. Keep a record of these settings as they will be used later in the configuration of the bindings.
  4. Right click on the Queues node under MQTest queue manager. Select New -> Local Queue.
  5. Enter 'MQSenderQueue' as the name for the local MQ queue. Click Next and Finish.
  6. Repeat the above two steps to create another local queue called 'MQReceiverQueue.'
  7. Create a new channel for the new MQTest Queue Manager.
    1. Expand Queue Managers -> MQTest -> Advanced -> Channels -> New -> Server-connection Channel
    2. Name: mysvrconnchannel
    3. Keep all other values as default.
    4. Click Next -> Finish.
  8. Create a new directory for the JNDI context environment. For example:
    mkdir /var/mqm/MQ-JNDI
  9. In the new directory create a file called mq-jndi.properties with the following content:
    INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
    PROVIDER_URL=file:/var/mqm/MQ-JNDI
    SECURITY_AUTHNTICATION=none
  10. Run the following command:
    ${MQ INSTALL DIRECTORY}/java/bin/JMSAdmin -v -cfg mq-jndi.properties
  11. At the presented prompt execute the following commands (use xa if is transactional; if not remove the xa):
    def xaqcf(MQSenderQCF) qmgr(MQTest) HOST(celvpint0912.us.oracle.com) PORT(1515) TRANSPORT(CLIENT) CHANNEL(mysvrconnchannel)
    def xaqcf(MQReceiverQCF) qmgr(MQTest) HOST(celvpint0912.us.oracle.com) PORT(1515) TRANSPORT(CLIENT) CHANNEL(mysvrconnchannel)
    def q(MQSenderQueue) qmgr(MQTest) queue(MQSenderQueue)
    def q(MQReceiverQueue) qmgr(MQTest) queue(MQReceiverQueue)
    end

    NOTE:
    • HOST: uses the hostname where MQ is installed
    • PORT: uses the port number that was defined when we created the new MQ Manager called MQTest
    • TRANSPORT: It should always use CLIENT when we have a client/server configuration. In other words, when MQ and WLS are running on different boxes.
    • CHANNEL: uses the channel name we defined for the new MQ Manager (defined above).
  12. In the directory where the file mq-jndi.properties was created (/var/mqm/MQ-JNDI) a new file called .bindings should have been created as a result of the commands in the previous step. This file is important when configuring the WLS side and we will need to transfer it to the WLS box.

Configuring the WLS Machine

Please follow these steps:

  1. Transfer the following jar files (located under /opt/mqm/java/lib in the machine where MQ is installed) into a directory on your WLS box. For example, create a directory called C:\mqlibs and put the following files there:
    • com.ibm.mq.jar
    • com.ibm.mqetclient.jar
    • com.ibm.mqjms.jar
    • commonservices.jar
    • dhbcore.jar
    • fscontext.jar
    NOTE: please note that com.ibm.mqetclient.jar in MQ7 is needed for XA.
  2. Create another directory as follows:
    mkdir C:\MQ-JNDI
  3. Transfer the .bindings file (notice the dot at the beginning of the filename) under /var/mqm/MQ-JNDI on the Linux box to the newly created directory C:\MQ-JNDI.
    NOTE: This step is critical as the transferred file contains the information on how to connect to the remote JMS server (the MQ server).
  4. Edit the setDomainEnv.cmd for the WLS domain and at the end of it add the following:
    SET CLASSPATH=C:\mqlibs\com.ibm.mqetclient.jar;C:\mqlibs\com.ibm.mqjms.jar;C:\mqlibs\commonservices.jar;C:\mqlibs\dhbcore.jar;C:\mqlibs\fscontext.jar;C:\mqlibs\com.ibm.mq.jar;%CLASSPATH%

Configuring WebLogic Server


  1. Create JMS Module
    1. Click Lock & Edit button; then from the left menu expand Services -> Messaging and click JMS Modules link.
    2. In the now opened JMS Module, click on the 'New' button to create the JMS module on WebLogic. Let's name this "MQIntegrationTest" in the Name text box. Press Next.
    3. Select the 'Target' server: for instance, Admin or MyManagedServer. Press Next and finally Finish.
    4. Click on Activate Changes button on the left menu to complete creation of JMS Module.
  2. Create a JMS Foreign Server on WebLogic Server.
    1. From WebLogic Administration Console, click on Lock & Edit again.
    2. Select Services -> Messaging -> JMS Modules and click on the newly created module "MQIntegrationTest."
    3. Once you are in the "MQIntegrationTest" module, click the 'New' button, select the 'Foreign Server' radio button, and continue by clicking Next.
    4. Name the new Foreign Server as "MQTestForeignServer" and click the Next button. On this page you can see that the target server is selected already for you. Click Finish.
    5. To persist this new JMS Foreign Server, click on the Activate Changes button.
    6. Now, to continue, click Lock & Edit again and open the newly created Foreign JMS server by clicking Services -> Messaging -> JMS Modules -> MQIntegrationTest -> MQTestForeignServer.
    7. From this "MQTestForeignServer" module, under the Configuration -> General tab, enter the following details:
      • JNDI Initial Context Factory: com.sun.jndi.fscontext.RefFSContextFactory
      • JNDI Connection URL: file:/C:/MQ-JNDI
    8. Click Save to finish the configuration of the JMS Foreign Server.
  3. Create JMS Destinations on WebLogic. We need to create two JMS Destinations on WebLogic "ReceiverDetails" and "ReplyDetails."
    1. Click Lock & Edit on WebLogic Administration Console and select Services -> Messaging -> JMS Modules -> MQIntegrationTest -> MQTestForeignServer.
    2. Click on the Destinations link in the Configuration tab at the top and click New.
    3. Following are the details for Destination:
      • Name: ReceiverDetails
      • Local JNDI Name: jms/WLReceiverQueue
      • Remote JNDI Name: MQSenderQueue
        NOTE: The Remote JNDI Name must match the name of the queue you created in IBM WebSphere MQ Broker.
    4. Click OK to complete configuring your "ReceiverDetails" Destination.
    5. Repeat the above step (i) through (iv) to create another Destination "ReplyDetails" with the following details:
      • Name: ReplyDetails
      • Local JNDI Name: jms/WLReplyQueue
      • Remote JNDI Name: MQReceiverQueue
    6. Now we have two Reply Queues.
  4. Create Connection Factories on WebLogic Server. Now we need to create two Foreign JMS Connection Factories for queues we created in Step 4.
    1. On the WebLogic Server Administration Console, select Services -> Messaging -> JMS Modules -> MQIntegrationTest -> MQTestForeignServer.
    2. Click on Connection Factories (next to Destinations) and click New.
    3. Enter the following details in the 'Create a New Foreign JMS Connection Factory' page.
      • Name: ReceiverCF
      • Local JNDI Name: jms/WLReceiverQCF
      • Remote JNDI Name: MQSenderQCF
        NOTE: The remote JNDI name must match the one you have given in your IBM WebSphere MQ Connection Factory.
    4. Click OK to complete creation of the "ReceiverCF" Connection Factory.
    5. Repeat the above steps to create one more Connection Factory for our Reply Queue:
      • Name: ReplyCF
      • Local JNDI Name: jms/WLReplyQCF
      • Remote JNDI Name: MQReceiverQCF
    6. Click on Activate Changes to persist the changes.
    7. Now you have the Connection Factory for Reply Queues.


    Configuring JMS


    1. Download the generic_message.jar file attached to this note which contains the class file for the MDB. Extract its content and modify the weblogic-ejb-jar.xml file to look as follows:
      <?xml version="1.0"?>
      <!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">
      <!-- Sample MessageDriven bean Weblogic deployment descriptor -->
      <weblogic-ejb-jar>
        <weblogic-enterprise-bean>
          <ejb-name>genhellomdb</ejb-name>
          <message-driven-descriptor>
            <destination-jndi-name>jms/WLReceiverQueue</destination-jndi-name>
            <connection-factory-jndi-name>jms/WLReceiverQCF</connection-factory-jndi-name>
          </message-driven-descriptor>
        </weblogic-enterprise-bean>
      </weblogic-ejb-jar>
      The important part here is the destination-jndi-name and the connection-factory-jndi-name. These should be the queue and JMS foreign server names used when WLS is configured.
    2. Jar the file again and then jar it into an ear file.
    3. Deploy the application.

    Testing the Configuration

    After making sure the application is deployed correctly, test the MDB by putting a test message in the MQ queue. Follow these steps:
    1. In the MQ Box where the WebSphere MQ explorer is running (application strmqcfg), navigate to Queue Managers -> MQTest -> Queues -> MQSenderQueue. Right-click on MQSenderQueue and select "Put Test Message." Set Message Data to "Hello!!"
    2. On the WLS side, the standard output should show the following:
      Got the Mesg with ID:ID:414d51204d51546573742020202020205dfeea5002fd0220 with Redelivered flag as : false
      Received the message : Hello!!
      This shows that the MDB running on the WLS side is working as expected and consuming messages put in on the MQ queue side.

    download file : generic_nessage.jar