Integrating BEA WebLogic Server with Websphere MQ

This article shows you how to configure and integrate BEA WebLogic Server as a foreign JMS provider for WebSphere MQ.

Sanjay M Kesavan (sanjay_mk@in.ibm.com), Senior Staff Software Engineer, WebSphere MQ Java/JMS Support team, IBM

Sanjay M Kesavan is a Senior Staff Software engineer on the WebSphere MQ Java and JMS Support team at the IBM India Software Lab in Bangalore, India. He has 12 years of IT experience and joined IBM in 2000, and has worked on WebSphere Application Server and WebSphere MQ. You can contact Sanjay at sanjay_mk@in.ibm.com.



26 April 2006

Introduction

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("MyMDBQueue")
    	DEFINE QLOCAL("MyReplyQueue")
    end

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:

INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL=file:/C:/JNDI-Directory
SECURITY_AUTHENTICATION=none

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)
end

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
           -Dweblogic.management.username=weblogic -Dweblogic.management.password=weblogic
           -Dweblogic.management.GenerateDefaultConfig=true weblogic.Server
  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
    set CLASSPATH=%MQ_JAVA%\com.ibm.mq.jar;%CLASSPATH%
    set CLASSPATH=%MQ_JAVA%\com.ibm.mqjms.jar;%CLASSPATH%;
    set CLASSPATH=%MQ_JAVA%\com.ibm.mqetclient.jar;%CLASSPATH%
        (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

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

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

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 wlresources.zip file that you can download below contains the sample application and the WLSampleMDB.ear file for deploying to WebLogic.

Extract wlresources.zip 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\SampleMDBBean.java
  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
    JMSCorrelationID:null
    JMSDestination: null
    JMSReplyTo: null
    JMSRedelivered: false
    JMS_IBM_PutDate:20060328
    JMSXAppID:WebSphere MQ\bin\amqsput.exe
    JMS_IBM_Format:MQSTR
    JMS_IBM_PutApplType:11
    JMS_IBM_MsgType:8
    JMSXUserID:sanjay
    JMS_IBM_PutTime:15302519
    JMSXDeliveryCount:1
    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.


Conclusion

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.


Download

DescriptionNameSize
Code samples in zip formatwlresources.zip  ( HTTP | FTP )9 KB

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=109786
ArticleTitle=Integrating BEA WebLogic Server with Websphere MQ
publish-date=04262006