This scenario describes a simple stock query application, which is written in Java™, that uses the Java
Message Service (JMS) API to interact with IBM® MQ. This
application is used by the IBMz/OS® Connect scenarios
to demonstrate two-way services with the IBM MQ service
provider.
The stock query application takes request messages from an IBM MQ queue. The messages contain the ID of the item that the caller wants information on.
The application then generates a response message that contains information on the requested item
and sends it to a response queue. The requesting application takes the response message from the
response queue.
Compiling the application
The code for the stock query application is shown in Figure 1.
To
compile the application, copy the sample code in Figure 1
to a file called TwoWayBackend.java on a UNIX System Services environment on a z/OS LPAR where
IBM MQ for z/OS is
installed, including the IBM MQ for z/OS
UNIX Systems Services Components feature.
Using a Java 7.1 or later Java SE Development Kit, enter
the following command to compile the application:
If necessary, replace /usr/lpp/mqm/V9R1M0/ with the path to the installation
of the IBM MQ for z/OS UNIX Systems Services Components feature.
Defining the queues for the application
Work with your IBM MQ administration to define a pair of
queues for use by the stock query application. Both a request and a response queue are needed. For
example, to define a request queue called STOCK_REQUEST and a response queue called STOCK_RESPONSE
enter the following MQSC commands:
DEF QL(STOCK_REQUEST)
DEF QL(STOCK_RESPONSE)
Running the application
To run the stock query application, first ensure that the UNIX System Services STEPLIB includes the IBM MQ
SCSQAUTH and SCSQANLE libraries. Specify these libraries in the startup JCL or using the
.profile file. From UNIX and Linux® System Services, you can include these
libraries by adding the following line to your .profile. Replace
thlqual with the high-level data set qualifier that you chose when installing IBM
MQ:
Enter the following command from UNIX System Services,
replacing MQ21 with the name of the queue manager where the STOCK_REQUEST and STOCK_RESPONSE queues
were defined. If necessary, replace both instances of /usr/lpp/mqm/V9R1M0/ with
the installation path of the IBM MQ for z/OS
UNIX System Services Components
feature.
If a problem occurs, exception
information is displayed that you can use to analyze the problem.
To stop the application, enter Ctrl+C in the command window where the
application was run.
Testing the application
Use MQ Explorer to connect to your MQ queue manager on z/OS and send a message to the STOCK_REQUEST queue. Use a message
payload value that consists of a six-digit integer, left padded with zeros. For example, 001234.
The following output is displayed by the stock query
application:
Waiting for message. Press Ctrl+C to exit.
Message received: 001234
Waiting for message. Press Ctrl+C to exit.
If
a problem occurs, exception information is displayed that you can use to analyze the problem.
You can now use IBM MQ Explorer to browse the response message on the STOCK_RESPONSE queue.