doc
Tutorial 7
MQSeries
In this exercise, we design a message queue, send a messages and read it back again.
Note: This tutorial was generated with the user-ID "PRAKT20". In all file names, you must replace
"PRAKT20" by your own user-ID. Moreover, PRAKTxx is used often in the text below, whereby the xx
should be your user ID.
MQSeries
For commercial Messaging and Queuing, MQSeries represents a platform independent
Middleware-product. It is used especially in high speed - implementations of distributed
applications. MQSeries is popular, because it is possible to develop and test MQSeries
applications with a minimum amount of time and resources.
Since MQSeries is capable of running on many different platforms, programs can as a result
work together over a network of different components, processors, subsystems, operating
systems and communication protocols. MQSeries-programs use a consistent application
interface (API) on all platforms. Figure 1 shows the main components of a MQSeries
application.
1
tutor07.doc
Both programs A and B use a special MQSeries Application program interface (API) in order
to write messages into the Queue and/or to read out of the Queue. The MQ Series-API is
named Message Queue interface (MQI).
It is possible that program B is not running when program A places a message into the
Queue. In this case, the Queue stores the message until program B is started and can
retrieve it. On the other hand, program A can be inactive when program B retrieves the
message out of the Queue. For MQSeries, it is not necessary that both communicating
programs must be simultaneously active. MQSeries makes asynchronous processing
possible.
Message
A message consists of two parts:
The message descriptor identifies the messages (with a message ID) and contains guiding
information (attributes), as well as a message-type, time-flow, correlation-ID, priority and
name of the answer queue.
The message length is dependent on the version of MQ Series being used. MQSeries
version 5 (for distributed platform) supports a maximal message-length of 100 MByte. On our
OS/390 system at the University of Leipzig, MQSeries version 2.1 has been installed and
supports messages up to 4 MByte.
Queue Manager
A Queue manager (QMGR) is the MQSeries software, that is assigned to a queue. It
administers the objects belonging to MQSeries, especially Queues, Channels, process
definitions, and others.
In addition, the Queue manager makes the Message Queue Interface (MQI) available. An
application the MQI to access queues and messages contained therein. The MQI
implements a simple application program interface that is identical for all supported
platforms. Through the MQI, the applications are separated from the Queue manager.
An application must establish a communication with the Queue manager before it can access
its resources. For this it uses the commands MQCONN or MQCONNX. If the application no
longer requires a connection to the Queue manager, MQDISC is used to disconnect,
In order to access a Queue, an application must first open this Queue. This is done by
means of the MQOPEN call. With MQCLOSE, the Queue is closed again.
With a queue opened, the application uses the command MQPUT in order to write a
message into a Queue. With the call MQGET, a message can be read out of the Queue. By
2
tutor07.doc
means of the call MQPUT1, an application can, in one step, open a queue, write messages
into the Queue and close the Queue again.
When installating MQSeries on a server, the Queue manager must be setup by a systems
programmer.
Queue
When an application writes a message into a Queue, the Queue manager will assure that the
message is savely stored, recoverable and is delivered only once at the receiving end. This
also applies if a message must be sent to a Queue of another Queue manager. This
mechanism within the framework of MQSeries is called "secured delivery".
There are persistent and non-persistent messages. Persistent messages are written in the
MQSeries log and are available again after a new start of the QMGRs. Non-persistent
messages are no longer available after a new start of the QMGRs.
When an application opens a Queue, the Queue manager determines whether we are
dealing with a "local Queue" or a "remote Queue". A local Queue is a queue that belongs to
the Queue manager which interacts with the application. A Queue is named as "remote" if it
belongs to another Queue manager.
When an application issues the command MQPUT, the Queue manager writes the message
to the local Queue. If it concerns a "remote" Queue, the Queue manager retrieves from its
definition the information that is necessary for correct delivery (name of the remote QMGR,
name of the remote Queue, name of the associated transmission Queue). The message is
placed is into an inbetween-Queue (transmission Queue), and is assigned to the remote
QMGR.
Subsequently it is the task of the message Channel agent (MCA) to read the message of the
transmission Queue and to send it over the network to a receiving MCA. The latter writes the
message into the taget-Queue. After this the message in the transmission Queue is deleted.
3
tutor07.doc
User Programs
Data exchange between two user-programs takes place via the MQI. The latter represents a
call interface with a limited number of calls and extensive options for each call. Preset
standard and start values guarantee a quick start.
The MQI uses a set of structures and constants. With MQSeries, files and copybooks are
included, that contain the definitions of these structures and their fields as well as the
definitions of symbolic names, that are used for constants within the program logic.
A program talks directly with its Queue manager. It resides on the same processor (or
domain for clients) as the program itself.
When the connection between a client and its server is interrupted, no API-Calls can be
carried out because all objects are on the server.
There exist a total of 13 APIs. They are listed in figure 20. The most important APIs
are:MQCONN, MQOPEN, MQPUT, MQGET, MQCLOSE and MQDISC.
4
tutor07.doc
MQCONN establishes a connection with a Queue-manager with the help of standard links.
MQBEGIN: starts a unit of work that is coordinated by the Queue-manager. It may contain
external XA-Compatible-resource-managers. This API was introduced with MQSeries version
5. It is used for the coordination of transactions, that use Queues (MQPUT and MQGET
under syncpoint-conditions) and database-updates (SQL commands).
MQPUT1: opens a Queue, transfers a message and closes the Queue again. This API-Call
represents a combination of MQOPEN, MQPUT and MQCLOSE.
MQINQ: Requests information over the Queue-manager or over one of its objects, like the
number of messages in a Queue.
MQCMIT: Indicates that a Syncpoint was reached. The messages are generated as part of a
Unit of Work and are made available for other applications. Returned messages are deleted.
MQBACK: Informs the Queue Manager about all returned PUT´s and GET´s messages
since the last Syncpoint. Messages that were generates as part of a Unit of work are deleted.
Returned messages are put on the Queue again.
MQDISC: includes the transfer of a working unit: The termination of a program without
interruption of the connection to the Queue-manager causes a "rollback" (MQBACK).
In order to carry out this exercise, it is necessary that the Queue manager has been
started. If this is not the case, an authorised user must start the Queue manager in
SDSF SYSLOG. The command looks like this:
5
tutor07.doc
For the communication of the two user-programs a "local Queue" is required. In order to
generate the latter, we select the "MQSeries for OS/390-Main Menu" of the Custompac
master application Menu (CMAM). For this we select "m" as an option and press the Enter-
key.
6
tutor07.doc
Connect to queue
manager . . . . . . :
Target queue manager :
Response wait time . : 30 seconds
In the Main Menu, we enter in the line "Action" a 2 (Define). As an "Object type" and "name"
we enter QLOCAL and/or PRAKTxx. All remaining entries remain as they are. A local Queue
is defined with the name "PRAKTxx". The latter belongs to the Queue manager MQA1.
Hint: If the error message "CSQO040I Object named PRAKT20 of type QUEUE already
exists" appears, then a local Queue already exists with the name PRAKTxx. Please delete
the old queue. Input a 4in the Panel "IBM MQSeries for OS/390 - Main Menu" in the line
"Action". For "Object type" and "name" enter QLOCAL and PRAKTxx. Assure that both lines
marked Queue Manager contain the entry "MQA1".
Hitting the entry key three times deletes the Queue. The message: "CSQ9022I! MQA1
CSQMUQLC ' DELETE QLOCAL' NORMALLY COMPLETION" confirms successful deletion.
Use the F6 key in order to activate/access Menu changes in the fields "Connect to QMGR"
and "Target QMGR" in the Menu.
7
tutor07.doc
By hitting the Enter key these values are received. We should see a screen similar to Fig. 4
Connect to queue
manager . . . . . . : MQA1
Target queue manager : MQA1
Response wait time . : 30 seconds
Subsequently hit the Enter-key. A further Screen appears as a result for the definition of the
local Queue.
8
tutor07.doc
Complete fields, then press F8 for further fields, or Enter to define queue.
More: +
In this Screen, the name of the Queue must be registered (PRAKTxx) once more. To enable
Put and Get, we select Y (Yes) for both. All other parameters are entered as shown in figure
5.
Subsequently we hit Key F8. The result is a 3 Define Screen (Fig.6) in which in the line
"Default persistence" = "N" (No) is entered. A message is called "persistent" if it is still
available after a restart of the Queue manager. It doesn’t matter whether the Queue manager
was stopped by an operator command or stopped by a system error. This means that
persistent messages are written into a protocol. If after an error a Queue manager is started
again, it reproduces the messages from the protocol data.
9
tutor07.doc
More: - +
More: - +
Trigger Definition
Via F8 another three define screens can be called. We do not take advantage of this and hit
<Enter> in the 3 define screen.
10
tutor07.doc
As a result of this action, the Screen "display messages" appears. It shows whether the
encountered definitions were successful for our local Queue "PRAKTxx" (fig. 7)
Complete fields, then press F8 for further fields, or Enter to define queue.
More: +
As a result of this action, the Screen appears "display messages" that issues, whether the
encountered definitions were successful for our local Queue "PRAKTxx" (fig. 8)
Connect to queue
manager . . . . . . : MQA1
Target queue manager : MQA1
Response wait time . : 30 seconds
11
tutor07.doc
This screen lists all local Queues with its definitions that begin with "P". With the key F11,
important parameters of the local Queues can be displayed on the screens. The result is
shown in figure 10.
Exercise: Set up a Local Queue with the name PRAKTxx (xx from your user ID) and check
whether your Queue was implemented correctly or not.
As the next step we generate the source code for the user-programs A and B in the
programming language COBOL II. Because we do not presume, that the participant has any
COBOL knowledge, we can simply copy the required source code for the programs A (PUT)
and B (GET) from the IBM MQSeries library. It will be under the directory MQM.SCSQCOBS.
The libraries already exist on the server in compiled form. In order to get an overview of both
of the COBOL program modules, we do the following: In the Custompac master application
Menu, we enter option P.3.4 and hit the enter key. As a result we obtain the Data List Utility
(figure 11)
12
tutor07.doc
Option ===>
F1=Help F3=Exit F10=Actions F12=Cancel
In this Screen on the line "Dsname level" enter the PDS-name "MQM. SCSQCOBS". This
library, together with MQM.SCSQCOBC forms an integral component of MQSeries . The first
library contains among others the COBOL II-source program module for PUT and GET
(.S -> source, while the second contains the copy book (...C ->Copy).
In the line, “Initial View”, a "2" is entered (Space). Subsequently we hit the Enter-key. The
following Screen “DSLIST- Data Sets Matching MQM.SCSQCOBS” displays the used
storage space on a 3390-Device. (figure 12)
13
tutor07.doc
We enter a "b" (for browse) before the file names MQM. SCSQCOBS and hit the Enter- key.
The result screen lists all members of this PDS as shown in Fig.11
When you enter the command "S" (Select) on the line in front of the Member CSQ4BVK1, the
source code of this module can be displayed (figure 12).
With the keys F8 and F7 we can scroll forwards or backwards.
14
tutor07.doc
By entering F3, one goes back into the list of members for MQM. SCSQCOBS. You can
inspect the source code for the members CSQ4BVJ1 by means of the select command on
the screen.
We now need two JCL scripts in order to send a message to the message queue MQA1 and
toreceive a message.
Before we copy these two modules, we need to create a private library with the name
PRAKTxx.MQA1.USERJCL. We do this as shown in Tutorial 1. Please enter the values as
showm in figure 15:
15
tutor07.doc
This PDS (partitioned data set) should receive the corresponding JCL-Script2 for the PUT
and GET jobs. We copy from the PDS MQM.SCSQPROC the Member CSQ4BVJR. This
member should be copied twice and named MQPUT and MQGET. We now have a JCL
script with the Members MQPUT and MQGET. MQPUT contains the job, that through calling
the module CSQ4BVK1 with the corresponding parameters (QMGR, QUEUE, MSGS, PAD,
LEN and PERS) writes a message into the local Queue and displays the result on the
screen. MQGET implements the job that reads this message through calling the module
CSQ4BVJ1 with identical parameters (as MQPUT) from the local Queue and displays the
results to the screen.
The copying can be done (option P.3.3) by means of the Move/Copy Utility.
16
tutor07.doc
Option ===> C
F1=Help F3=Exit F10=Actions F12=Cancel
We input the values as indicated above, hit the Enter-key and arrive at the following Screen:
To ISPF Library:
Project . . PRAKT20 Replace option:
Group . . . MQA1 Enter "/" to select option
Type . . . . USERJCL Replace like-named members
Member . . . MQGET (Blank unless member is to be renamed)
We copy the same Member once again, but now store it under
PRAKTxx.MQA1.USERJCL.MQPUT
17
tutor07.doc
Exercise: Generate the new Dataset and copy the JCL scripts 2 times (as a MQGET and
MQPUT).
Now we edit the members MQPUT and MQGET. Both files are JCL scripts that must be
adapted for our purposes: We open MQPUT by means of the TSO editor:
Using the F7 or F8 keys, we can display the source text by scrolling. You can see that the
script has plenty of comments. (The actual script has only 8 lines).
18
tutor07.doc
If we go to line 56:
The parameters starting at line 56 are very well documented in the script. We replace this
line by:
19
tutor07.doc
This means: 3 messages are written into the local Queue whereby each messages consists
of a sequence "ZZZZZ". After editing the parameters, we enter "SUB" on the command line.
The command “SUB” is confirmed by means of “Enter” and the following screen appears:
20
tutor07.doc
Here we can simply enter P (for Put). Background: the job gets a name that consists of the
login (PRAKTxx) and the entered character (above). (Maximally 8 characters). So our job is
named PRAKTxxP.
21
tutor07.doc
22
tutor07.doc
Now these messages must be retrieved. We edit the Member MQGET from the directory
PRAKTxx.MQA1.USERJCL.
It is the same JCL script as for MQGET. We scroll with F8 directly to line 56 and replace the
line with:
23
tutor07.doc
By entering “sub“ we run the script. The jobname should now be PRAKTxxG, therefore enter
a “G”.
Exercise: Repeat the scripts MQPUT and after that MQGET again.
After a successful run, we may ask ourselves, what has actually happened:
After repeatedly hitting the F3key, we arrive back at the Custompac master application
Menu. Subsequently we enter on the line "option" SD and arrive therewith into the SDSF
panel.
24
tutor07.doc
5647-A01 (C) Copyright IBM Corp. 1981, 1997. All rights reserved.
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
Enter “ST“ (status) on the command line. Confirm your action by pressing “Enter”
On the line of the job-number, we input a S (Select) and confirm with Enter. Now our script is
displayed; we scroll to the results at the end:
25
tutor07.doc
Here we see what the script actually did, a MQCONN, MQOPEN, three messages created,
MQCLOSE and MQDISC. We go back with F3 and observe the result of PRAKTxxG.
26
tutor07.doc
27