You are on page 1of 38

Write Java Message Service programs using

WebSphere MQ Version 6 and Rational


Application Developer Version 6, Part 1: Installing
the software and running your first programs
Skill Level: Intermediate

Willy Farrell (willyf@us.ibm.com)


Senior Software Engineer
IBM

09 May 2006

Get an overview of enterprise messaging systems and Java™ Message Service


(JMS) in this tutorial from developerWorks. Explore the latest tools from IBM for JMS
development and testing (including WebSphere® MQ V6 and IBM Rational®
Application Developer V6). You get detailed instructions about how to obtain, install,
and configure these tools. And you also use sample programs and instructions about
how to run them so you can easily use the tools and understand their capabilities.

Section 1. Before you start


To get the most out this tutorial, you need to:

• Download a free trial version of WebSphere MQ Version 6.0.


• Download a free trial version of Rational Application Developer Version
6.0.

About this tutorial


In this tutorial you get a step-by-step approach to installing and configuring
WebSphere MQ and Rational Application Developer for developing JMS

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 38
developerWorks® ibm.com/developerWorks

applications. Sample applications are provided along with instructions for running
those applications using the installed products.

Objectives

• Install and configure IBM tools to create a JMS development environment.


• Configure and run JMS programs in that environment.

Prerequisites
This tutorial is intended for Java programmers who need to understand how to write
and test JMS programs using WebSphere MQ and Rational Application Developer.
Intermediate knowledge of Java and introductory knowledge of JMS is assumed.

System requirements
The instructions in this tutorial are for use in a Windows environment, though
readers knowledgeable in other operating systems can probably adapt them for use
in their operating system.

The system requirements for the products used in the tutorial can be found through
the following links:
• WebSphere MQ
• Rational Application Developer

Section 2. Introduction

Enterprise messaging systems


Enterprise messaging systems, sometimes called message-oriented middleware
(MOM), have long been important tools for application integration. They provide a
flexible, loosely coupled means of exchanging information between applications.
Acting as an intermediary, the MOM delivers data (messages) between applications
using a store and forward mechanism. The applications do not communicate directly
with each other, but instead communicate with the MOM, which routes messages as

Installing the software and running your first programs


Page 2 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

required. In today's computing environment, with the emphasis on services and


service-oriented architecture (SOA), MOM plays a vital role as the connectivity layer
of such an architecture. IBM WebSphere MQ is a long-established enterprise
messaging system and is a leader in this market.

Java Message Service


In the past, each MOM vendor typically provided a proprietary application
programming interface (API) to be used with their product. When a third-party
vendor wanted to, for example, use messaging to integrate their application with an
enterprise resource planning (ERP), supply chain management (SCM), or other
application, they had to write separate and different messaging components within
their applications, and separate and different adapters for the ERP or SCM or other
system, to utilize whichever MOM their customers had installed. As the number of
MOM vendors grew, this caused development and maintenance headaches.

The Java Message Service (JMS) provides a standard, portable way for Java
programmers to access MOM products. The key to JMS portability is that the API is
defined as a set of interfaces; MOM vendors deliver a provider that implements
those interfaces for their particular product. Additionally, JMS resources are
accessed through the Java Naming and Directory Interface (JNDI), providing
additional portability and abstraction. Using JMS, Java programmers retrieve JMS
resources, called administered objects, from JNDI and access them through the
standard JMS interfaces, relieving them from having any knowledge of the details of
the underlying messaging system. WebSphere MQ has a built-in JMS provider.

Rational Application Developer


IBM Rational Application Developer (Application Developer) is the latest integrated
development environment (IDE) from IBM for Java 2 Platform, Enterprise Edition
(J2EE) development. Application Developer is built on the Eclipse platform and is
optimized for developing applications to run on the WebSphere platform, although it
does support other vendors' runtime environments. The WebSphere Application
Server V6 integrated test environment supplied with Application Developer provides
a built-in JMS provider, the Service Integration Bus (SIB). You can use this SIB for
testing JMS applications without installing a separate enterprise messaging system.

Section 3. Install the software

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 38
developerWorks® ibm.com/developerWorks

Let's get to some hands-on stuff! In this section, you go through the steps to install
the software needed to complete this tutorial.

Install WebSphere MQ

1. Download the trial version of WebSphere MQ V6. (See Resources for a


link.)

2. Extract the downloaded file, WMQv600Trial-x86_win.zip, to a folder on


your system.

3. Launch MQLaunch.exe from the folder to which you extracted the


downloaded file.

4. Click Software Requirements on the navigation bar on the left, then click
+ next to WebSphere Eclipse Platform Version 3.0.1. (See Figure 1).

Figure 1. WebSphere MQ software requirements

5. Click CD-ROM to install the WebSphere Eclipse Platform. Accept all


defaults during this installation.

Installing the software and running your first programs


Page 4 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

6. Once the WebSphere Eclipse Platform is installed, click Network


Configuration on the navigation bar on the left.

7. Select the No radio button.

8. Click WebSphere MQ Installation on the navigation bar on the left.

9. Click Launch IBM WebSphere MQ Installer.

10. After accepting the license agreement terms, select Custom as the setup
type.

11. Click Next.

12. You need to change the default installation folders, so click Change.

13. Enter C:\WSMQ in the Folder name: field. (See Figure 2.)

Figure 2. WebSphere MQ destination folder

14. Click OK. Accept all remaining defaults to complete installation.

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 5 of 38
developerWorks® ibm.com/developerWorks

15. Once WebSphere MQ installation is complete, the Prepare WebSphere


MQ Wizard will be launched. Click Next.

16. Accept all defaults. (Do NOT set up the default configuration.)

17. On the last screen of the Prepare WebSphere MQ Wizard, uncheck all
options and click Finish.

Install required WebSphere MQ SupportPacs


SupportPacs constitute a library of material that complements the WebSphere MQ
family of products. For this tutorial, we are going to use SupportPac MS0N - GUI
version of the existing JMS Admin tool. This SupportPac provides a graphical user
interface for managing JMS administered objects. This SupportPac requires two
additional SupportPacs to work properly.
• ME01: WebSphere MQ Initial Context Factory, which provides JNDI
capabilities within WebSphere MQ
• MS0B: Java classes for PCF, which provides support for Programmable
Command Format commands (PCF is an API for programmatically
administering WebSphere MQ.)

The SupportPacs consist of .zip files that contain JAR files and documentation.
You'll need these JAR files to set up JMS-administered objects and run the sample
programs later.

1. Download SupportPac MS0N - GUI version of the existing JMS Admin


tool (See Resources for a link.)

2. The download page for SupportPac MS0N also has links to download
SupportPacs ME01 and MS0B.

3. Once you have the three files (ms0n.zip, me01.zip, and ms0b.zip)
downloaded, extract each file to a folder named MQTools. (I put the
MQTools folder on my Windows desktop, but you can put it where it suits
you.)

Install Rational Application Developer

1. Download the trial version of Rational Application Developer V6 (see


Resources for a link). Download each of the following files to the same

Installing the software and running your first programs


Page 6 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

folder on your system:


• Part 1 - extractor.exe
• Part 2 - C81N0ML.bin
• Part 5 - C81N3ML.bin
• Part 6 - C81N4ML.bin

2. When all four files have been downloaded, launch extractor.exe to extract
the installation image to a directory on your system.

3. The extractor will provide a default location for the installation image. You
can change this to any directory that suits you.

4. Select the following features when prompted:


• Core installation files
• WebSphere Application Server V6.0 Integrated Test Environment
• IBM Agent Controller

5. Once the installation image is created, select the checkbox Start the
installation wizard now and click Finish.

6. On the Rational Software Development Platform Launchpad, click Install


Rational Application Developer V6.0 Trial.

7. Once the installer has started, accept the license agreement. Change the
installation directory to C:\RAD (See Figure 3).

Figure 3. Application Developer install directory

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 7 of 38
developerWorks® ibm.com/developerWorks

8. Accept all remaining defaults to complete installation.

9. When the installer indicates that Application Developer is successfully


installed, click Next.

10. Ensure the Launch Agent Controller install check box is checked and
click Finish.

11. When the Agent Controller installer starts, accept all defaults until the
Java Runtime dialog.

12. Enter C:\RAD\eclipse\jre\bin\java.exe for the location of the


Java Runtime file. (See Figure 4.)

Figure 4. Java Runtime file location

Installing the software and running your first programs


Page 8 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

13. Accept all remaining defaults to complete installation.

You now have all of the software installed. In the next section, you'll install the
sample code.

Section 4. Install the sample code

1. Download the sample code file, i-mqrad1code.zip. (See Download for a


link).

2. Extract this file to a folder on your system. On my system, I extracted it to


a folder named mq6rad6_1 on my Windows desktop. There are two files
in this folder: MQP2P.zip and EMQP2P.zip.

3. Launch Application Developer from the Start menu.

4. When prompted for a workspace, enter C:\workspace. (See Figure 5.)

Figure 5. Workspace location

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 9 of 38
developerWorks® ibm.com/developerWorks

5. Click OK.

6. Once Application Developer starts, close the Welcome screen by clicking


the X next to Welcome.

7. Switch to the Java perspective by selecting Window from the main menu,
then selecting Open Perspective > Java.

8. From the main menu, select File > Import.

9. Select Project Interchange as the import source and click Next.

10. In the From zip file: field, enter the location of the MQP2P.zip file
extracted previously. (See Figure 6.)

Figure 6. Project interchange zip file location

Installing the software and running your first programs


Page 10 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

11. Select the checkbox next to the MQP2P project, and click Finish.

Section 5. Review the sample code


Before we go on, let's take a look at the code in some detail. Three of the classes
that were imported - ConnectionPanel, QSenderUI, and QReceiverUI. Supply

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 11 of 38
developerWorks® ibm.com/developerWorks

the user interfaces for the programs using standard Abstract Windowing Toolkit
(AWT) facilities. (Because no JMS code is in these classes, we don't need to spend
any time going over them.)

QSender class
The first class with JMS code to look at is QSender. This class is used by
QSenderUI to send messages to a queue. Three methods in this class contain JMS
code: setConnection(), setQueue(), and sendMessage().
setConnection(), shown in Listing 1.

Listing 1. Three methods in QSender class containing JMS

public void setConnection(String connectionName)


throws JMSException, NamingException, Throwable {
try {
close();
QueueConnectionFactory factory =
(QueueConnectionFactory) getInitContext().lookup(connectionName);
connection = factory.createQueueConnection();
session =
connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
} catch (Throwable e) {
setExceptionMessage(e);
throw e;
}
}

This method takes as input the name of a QueueConnectionFactory which is


available in the JNDI namespace. The call to close(), a method within this class,
ensures that all QueueSender, QueueSession, and QueueConnection objects
are closed. Then, a lookup is done through JNDI to retrieve the
QueueConnectionFactory with the name passed in as the connectionName
parameter. Once the QueueConnectionFactory has been retrieved, it is used to
create a QueueConnection, which is in turn used to create a QueueSession.

Note that in this method, and all the other methods, containing JMS code that we will
look at, all code is in terms of JMS interfaces -- there is no WebSphere MQ-specific
code anywhere.

Next, examine setQueue(), shown in Listing 2. This method is called by


QSenderUI when the JNDI name of a Queue is entered in the user interface.

Listing 2. Examine setQueue()

public void setQueue(String queueName)


throws JMSException, NamingException, Throwable {

Installing the software and running your first programs


Page 12 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

try {
if (connection != null)
connection.stop();
if (sender != null)
sender.close();
Queue queue = (Queue) getInitContext().lookup(queueName);
sender = session.createSender(queue);
sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
sender.setPriority(4);
sender.setTimeToLive(0);
connection.start();
} catch (Throwable e) {
setExceptionMessage(e);
throw e;
}
}

First, the QueueConnection is stopped and the QueueSender is closed, if


needed. Then the Queue object is retrieved from JNDI using the queueName
parameter. Next a QueueSender is created to send messages to the Queue, and
attributes of the QueueSender are set. Finally, the QueueConnection is started,
permitting access to the messaging system.

The final method we cover in QSender is sendMessage(), shown in Listing 3. This


method is called when a message is to be sent to the Queue through the
QueueSender object.

Listing 3. sendMessage()

public void sendMessage(String text) throws JMSException, Throwable {


if (sender != null) {
try {
TextMessage message = session.createTextMessage(text);
sender.send(message);
} catch (Throwable e) {
setExceptionMessage(e);
throw e;
}
}
}

The QueueSession objects is used to create a TextMessage using the text


parameter, then the QueueSender object is used to send the message.

QReceiver class
Now, take a look at the QReceiver class. It also contains setConnection() and
setQueue() methods. Because the setConnection() method is identical to that
in QSender, I'll skip over it here. Below is the setQueue() method, shown in
Listing 4.

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 13 of 38
developerWorks® ibm.com/developerWorks

Listing 4. setQueue()

public void setQueue(String queueName)


throws JMSException, NamingException, Throwable {
try {
if (connection != null)
connection.stop();
if (receiver != null)
receiver.close();
Queue queue = (Queue) getInitContext().lookup(queueName);
receiver = session.createReceiver(queue);
receiver.setMessageListener(this);
connection.start();
} catch (Throwable e) {
setExceptionMessage(e);
throw e;
}
}

The obvious difference in the setQueue() method here and the setQueue()
method in QSender is that a QueueReceiver is created instead of a
QueueSender. But there is one more thing to look at. Notice the
setMessageListener() call. The QReceiver class is an implementation of the
javax.jms.MessageListener interface. By setting a MessageListener in the
QueueReceiver, messages that are received at the queue are passed
asynchronously to the MessageListener object. This allows the
MessageListener to process the messages as they arrive, and the receiver does
not have to query the Queue for new messages.

The MessageListener interface defines one method, onMessage(). Because the


QReceiver class implements that interface, it has an onMessage() method,
shown in Listing 5.

Listing 5. setQueue()

public void onMessage(Message message) {


String msgText = null;
try {
msgText = ((TextMessage) message).getText();
} catch (Throwable e) {
setExceptionMessage(e);
msgText = getExceptionMessage();
} finally {
setMessage(msgText);
}
}

This method is called by JMS each time that a message arrives on the Queue that is
being listened to. Here, the text of the message is used to set the message property
of the QReceiver object.

Installing the software and running your first programs


Page 14 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

The other methods of QSender and QReceiver classes are fairly self-explanatory
and take care of JNDI access, bound properties, and exception handling.

Section 6. Configure the WebSphere MQ runtime


environment
Before you can run the sample programs, you need to configure the runtime
environment to provide a WebSphere MQ queue manager and JMS administered
objects.

Create a queue manager

1. Launch WebSphere MQ Explorer from the Start menu.

2. In the Navigator view on the left, right-click Queue Managers and select
New > Queue Manager.

3. In the Queue manager name: field, type Ender.

4. Check the Make this the default queue manager checkbox.

5. In the Dead letter queue: field, type SYSTEM.DEAD.LETTER.QUEUE


(case is important).

6. The Create Queue Manager dialog should look like Figure 7.

Figure 7. Create Queue Manager dialog

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 15 of 38
developerWorks® ibm.com/developerWorks

7. Click Finish.

8. Close WebSphere MQ Explorer.

Create JMS administered objects


You will use the JMS Admin GUI provided by SupportPac MS0N to create the JMS
administered objects. Using this tool in conjunction with the JNDI support provided
by SupportPac ME01 allows you to create JMS administered objects directly in
WebSphere MQ, with WebSphere MQ providing JNDI facilities and without the need

Installing the software and running your first programs


Page 16 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

of a separate JNDI server. You can run the JMS Admin GUI from within Application
Developer.

Import JMS Admin GUI

First you'll need to set up a Java project which includes the JMS Admin GUI JAR file.

1. From the main menu, select File > New > Project.

2. Select Java project and click Next.

3. In the Project name: field, type JMSAdminGUI.

4. Click Next.

5. Click the Libraries tab.

6. Click Add External JARs.

7. Navigate to the MQTools folder to which you extracted the SupportPac


downloads.

8. Select the jmsadmingui.jar file. (See Figure 8.)

Figure 8. Select jmsadmingui.jar

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 17 of 38
developerWorks® ibm.com/developerWorks

9. Click Open and click Finish.

Run JMS Admin GUI

Now you can run the tool and create the JMS administered objects.

1. In the Package Explorer, expand JMSAdminGUI, then jmsadmingui.jar,


followed by com.ibm.mq.jms.admin.

2. Right-click JMSAdminGUI.class, and select Run > Run. (See Figure 9.)

Figure 9. Run JMSAdminGUI.class

Installing the software and running your first programs


Page 18 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

3. Select Java Application in the Configurations list.

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 19 of 38
developerWorks® ibm.com/developerWorks

4. Click New. Ensure that the Run dialog looks like Figure 10.

Figure 10. JMSAdminGUI run configuration

5. WebSphere MQ uses Java Native Interface (JNI) to invoke native code


for the particular operating system on which it is deployed. To ensure that
this code is available to the Java Runtime Environment (JRE) and that the
JRE native code is also available, you need to set the

Installing the software and running your first programs


Page 20 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

sun.boot.library.path system variable to point to the appropriate


folders.

6. Click the Arguments tab.

7. In the VM arguments text area, type


-Dsun.boot.library.path=C:\RAD\eclipse\jre\bin;C:\WSMQ\Java\lib.
Be sure you include the hyphen at the beginning, and type it all with no
spaces or carriage returns.

8. The JMS Admin GUI is dependent on classes included with the


SupportPacs and on classes provided with the WebSphere MQ Java
library. You need to set the runtime classpath to ensure those classes are
available.

9. Click the Classpath tab.

10. Click Bootstrap Entries in the Classpath: list.

11. Click Add External JARS.

12. Navigate to the MQTools folder and select the three JAR files there. (Use
Ctrl + click to select multiple files.)
• com.ibm.mq.pcf.jar
• jmsadmingui.jar
• mqcontext.jar

13. The JAR selection dialog should look like Figure 11.

Figure 11. MQTools JAR selection

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 21 of 38
developerWorks® ibm.com/developerWorks

14. Click Open.

15. Click Add External JARS again.

16. Navigate to C:\WSMQ\Java\lib and select the following JAR files:


• com.ibm.mq.jar
• com.ibm.mqjms.jar
• connector.jar
• dhbcore.jar
• jms.jar

17. The JAR selection dialog should look like Figure 12.

Figure 12. WSMQ\Java\lib JAR selection

Installing the software and running your first programs


Page 22 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

18. Click Open.

19. Click Run.

20. Click the Create a new config profile radio button, then click OK.

21. Type WMQ in the File Name field, then click Create.

22. Type Ender in the Provider URL field.

23. Select com.ibm.mq.jms.context.WMQInitialContextFactory in the


Initial Context Factory drop-down.

24. You JNDI Configuration dialog should look like Figure 13.

Figure 13. JNDI Configuration dialog

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 23 of 38
developerWorks® ibm.com/developerWorks

25. Click OK.

26. From the main menu, select Object > New > Queue.

27. Type EnderQ in the Object Name: field, then click OK.

28. Exit the JMS Admin GUI.

Section 7. Run the sample programs with WebSphere


MQ
Now you are ready to run the sample programs. As with the JMS Admin GUI, you'll
need to set the VM arguments and classpath to ensure the programs are configured
properly

Run QReceiverUI

1. Right-click QReceiverUI in the MQP2P project, and select Run > Run.

2. Select Java Application in the Configurations list.

3. Click New. Ensure that the Run dialog looks like Figure 14.

Figure 14. QReceiverUI run configuration

Installing the software and running your first programs


Page 24 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

4. Click the Arguments tab.

5. In the VM arguments text area, type the following arguments, each


separated by a space.
• -Djava.naming.factory.initial=com.ibm.mq.jms.context.WMQInitia
• -Djava.naming.provider.url=Ender

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 25 of 38
developerWorks® ibm.com/developerWorks

• -Dsun.boot.library.path=C:\RAD\eclipse\jre\bin;C:\WSMQ\Java\li
Other than the space between the arguments, there should be no other
spaces or carriage returns. Be sure to include the hyphen before each
argument. The arguments will wordwrap in the VM arguments text area.
This is OK as long as you do not type spaces (other than the ones
between the arguments) or carriage returns.

6. Click the Classpath tab.

7. Click Bootstrap Entries in the Classpath list.

8. Click Add External JARS.

9. Navigate to the MQTools folder and select the following JAR files:
• com.ibm.mq.pcf.jar
• mqcontext.jar

10. Click Open.

11. Click Add External JARS again.

12. Navigate to C:\WSMQ\Java\lib and select the following JAR files:


• com.ibm.mq.jar
• com.ibm.mqjms.jar
• connector.jar
• dhbcore.jar
• jms.jar

13. Click Open.

14. Click Run.

15. Type Ender in the Connection field and press Enter or click Set.

16. Type EnderQ in the Queue field and press Enter or click Set.

Run QSenderUI
To create the configuration for QSenderUI, you can duplicate the QReceiverUI
configuration, then change the configuration name and main class.

Installing the software and running your first programs


Page 26 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

1. Return to Application Developer.

2. From the main menu, select Run > Run.

3. Right-click QReceiverUI in the Configurations list and select Duplicate.

4. Rename QReceiverUI (1) to QSenderUI.

5. Change the Main class field to com.ibm.qbda.mq.p2p.QSenderUI.

6. Click Apply. Ensure the run dialog looks like Figure 15.

Figure 15. QSenderUI run configuration

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 27 of 38
developerWorks® ibm.com/developerWorks

7. Click Run.

8. Type Ender in the Connection field and press Enter or click Set.

9. Type EnderQ in the Queue: field and press Enter or click Set.

Test the programs

Installing the software and running your first programs


Page 28 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

1. Make both the Queue Sender and Queue Receiver windows visible.

2. Type text into the Message field of Queue Sender and press Enter or
click Set.

3. You should see the message text appear in the Queue Receiver window.

4. When you are finished, close both windows by clicking the X in the
upper-right corner.

Section 8. Configure the WebSphere Integrated Test


Environment
As mentioned in the introduction, the WebSphere Application Server V6 integrated
test environment included with Application Developer provides a built-in JMS
provider. In this section, you will configure a queue and JMS administered objects so
that you can run versions of the sample programs in the test environment.

Create a service bus and queue

1. From the main menu, select Window > Open Perspective > J2EE.

2. Select the Servers view, at the bottom of the window.

3. Right-click WebSphere Application Server V6.0 and select Start.

4. Wait for the status of the server to change to Started.

5. Right-click the server and select Run administrative console.

6. When the console appears, log in with any user ID.

7. Click Service Integration from the navigation bar on the left.

8. Click Buses.

9. Click New.

10. Type BeanBus in the Name field.

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 29 of 38
developerWorks® ibm.com/developerWorks

11. Click OK.

12. Click BeanBus from the Buses list.

13. Click Bus members from the Additional properties list. See Figure 16.

Figure 16. Buses additional properties

14. Click Add.

15. Click Next, then Finish.

16. Click Save at the top of the page, then click Save.

17. Click the BeanBus link at the top of the page. (See Figure 17.)

Figure 17. Bus members

Installing the software and running your first programs


Page 30 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

18. Click Destinations in the Additional Properties list.

19. Click New.

20. Select the Queue radio button.

21. Click Next.

22. Type BeanQ in the Identifier field.

23. Click Next.

24. Click Next again, then click Finish.

25. Click Save at the top of the page, click Save.

Create JMS administered objects

1. On the navigation bar to the left, click Resources > JMS Providers >
Default messaging. (See Figure 18.)

Figure 18. Default messaging navigation selection

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 31 of 38
developerWorks® ibm.com/developerWorks

2. Click JMS queue connection factory in the Connection Factories list.

3. Click New.

4. Type BeanQCF in the Name field.

5. Type jms/BeanQCF in the JNDI name field.

6. Select BeanBus from the Bus name drop-down.

7. Click OK.

8. Click Default messaging on the navigation bar to the left.

9. Click JMS queue from the Destinations list.

10. Click New.

11. Type MyBeanQ in the Name field.

12. Type jms/MyBeanQ in the JNDI name field.

13. Select BeanBus from the Bus name drop-down.

14. Select BeanQ from the Queue name drop-down.

15. Click OK.

16. Click Save at the top of the page, then click Save.

Installing the software and running your first programs


Page 32 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

17. Close the Admin Console.

18. Right-click WebSphere Application Server V6.0 in the Servers view and
select Restart > Start.

Section 9. Run the sample programs with WebSphere


Test Environment
When writing a desktop application to connect to an application server, it is best to
package that application as an application client module of an enterprise application.
This ensures that all of the resources needed to connect to the server are available.

In this section, you will import projects that have the sample programs repackaged
as application clients. Once you've completed that, you can run the programs to use
the built-in messaging of the test environment.

Import the repackaged sample programs

1. From the main menu, select File > Import.

2. Select Project Interchange as the import source and click Next.

3. In the From zip file field, enter the location of the EMQP2P.zip file
extracted previously from the sample code download file.

4. Click Select All.

5. Click Finish.

If you look at the application client projects, you will see that each one has a Main
class with a main() method. The main() method of the Main class in EQSender
calls QSenderUI.main(). Likewise, the main() method of the Main class in
EQReceiver calls QReceiverUI.main().

Run EQReceiver

1. Right-click EQReceiver and select Run > Run.

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 33 of 38
developerWorks® ibm.com/developerWorks

2. Select WebSphere V6.0 Application Client in the Configurations list.

3. Click New.

4. Change the Name field to EQReceiver.

5. Click Run.

6. Type jms/BeanQCF in the Connection field and press Enter or click Set.

7. Type jms/MyBeanQ in the Queue field and press Enter or click Set.

Run EQSender

1. Back in Application Developer, right-click EQSender and select Run >


Run.

2. Select WebSphere V6.0 Application Client in the Configurations list.

3. Click New.

4. Change the Name field to EQSender.

5. Click Run.

6. Type jms/BeanQCF in the Connection: field and press Enter or click


Set.

7. Type jms/MyBeanQ in the Queue field and press Enter or click Set.

Test the programs

1. Make both the Queue Sender and Queue Receiver windows visible.

2. Type text into the Message: field of Queue Sender and press Enter or
click Set.

3. You should see the message text appear in the Queue Receiver window.

4. When you are finished, close both windows by clicking the X in the
upper-right corner.

5. Stop the server test environment before closing Application Developer.

Installing the software and running your first programs


Page 34 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

Section 10. Summary


You have now downloaded and installed IBM's latest tools for developing,
configuring, and testing JMS programs: WebSphere MQ and Rational Application
Developer. You have also run some sample programs to demonstrate how these
tools work together to provide a complete environment for JMS development.

In the next tutorial, you'll look at JMS publish-subscribe programs. You will also look
at some other WebSphere MQ configurations that can make your programs more
flexible.

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 35 of 38
developerWorks® ibm.com/developerWorks

Downloads
Description Name Size Download method
sample code i-mqrad1code.zip 36KB HTTP

Information about download methods

Installing the software and running your first programs


Page 36 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®

Resources
Learn
• In "Introducing the Java Message Service" (developerWorks, June 2004), learn
the basics for writing JMS applications.
• Learn more about the Java Message Service at Sun's site.
• Visit the WebSphere MQ Roadmap to learn more about WebSphere MQ.
• Visit the "Rational Application Developer Roadmap" to learn more about
Rational Application Developer.
• "Developing a standalone Java application for WebSphere MQ"
(developerWorks, Feb 2005) shows how to develop an application that sends
and receives messages using WebSphere MQ that does not require being
deployed in a J2EE application server.
• In "Using WebSphere MQ with WebSphere Application Server Community
Edition" (developerWorks, Jan 2006), learn how to configure WebSphere
Application Server Community Edition to use WebSphere MQ as its JMS
provider.
• "Grouping messages using the WebSphere MQ Java and JMS APIs"
(developerWorks, Feb 2006) provides examples of WebSphere MQ's message
group support using JMS.
• Stay current with developerWorks technical events and webcasts.
Get products and technologies
• Download a free trial version of WebSphere MQ Version 6.0.
• Download a free trial version of Rational Application Developer Version 6.0.
• Download the SupportPac MS0N - GUI version of the existing JMS Admin tool.
This page also has download links to the other SupportPacs used in this
tutorial: ME01 - WebSphere MQ Initial Context Factory and MS0B - Java
classes for PCF.
• Build your next development project with IBM trial software, available for
download directly from developerWorks.
Discuss
• Participate in the discussion forum for this content.
• Participate in developerWorks blogs and get involved in the developerWorks
community.

Installing the software and running your first programs


© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 37 of 38
developerWorks® ibm.com/developerWorks

About the author


Willy Farrell
Willy Farrell is a Senior Software Engineer in the IBM Developer Skills Program. As
part of the developerWorks team, he provides relevant technical information and
insight to developers on the latest e-business and industry trends and technologies
through Web content, articles, speaking engagements, and consulting to faculty at
IBM Scholars Program member universities. He has been programming computers
for a living since 1981, began using Java in 1996, and joined IBM in 1998. You can
reach Willy at willyf@us.ibm.com.

Trademarks

Installing the software and running your first programs


Page 38 of 38 © Copyright IBM Corporation 1994, 2008. All rights reserved.

You might also like