4 min read

(For more resources on IBM, see here.)

WebSphere MQ sample programs—server

There is a whole set of sample programs available to the WebSphere MQ administrator. We are interested in only a couple of them: the program to put a message onto a queue and a program to retrieve a message from a queue. The names of these sample programs depend on whether we are running WebSphere MQ as a server or as a client.

There is a server sample program called amqsput, which puts messages onto a queue using the MQPUT call. This sample program comes as part on the WebSphere MQ samples installation package, not as part of the base package.

The maximum length of message that we can put onto a queue using the amqsput sample program is 100 bytes.

There is a corresponding server sample program to retrieve messages from a queue called amqsget.

Use the sample programs only when testing that the queues are set up correctly—do NOT use the programs once Q Capture and Q Apply have been started. This is because Q replication uses dense numbering between Q Capture and Q Apply, and if we insert or retrieve a message, then the dense numbering will not be maintained and Q Apply will stop. The usual response to this is to cold start Q Capture!

To put a message onto a Queue (amqsput)

The amqsput utility can be invoked from the command line or from within a batch program. If we are invoking the utility from the command line, the format of the command is:

$ amqsput <Queue> <QM name> < <message>

We would issue this command from the system on which the Queue Manager sits. We have to specify the queue (<Queue>) that we want to put the message on, and the Queue Manager (<QM name>) which controls this queue. We then pipe (<) the message (<message>) into this. An example of the command is:

$ amqsput CAPA.TO.APPB.SENDQ.REMOTE QMA < hello

We put these commands into an appropriately named batch fle (say SYSA_QMA_TESTP_UNI_AB.BAT), which would contain the following:

Batch file—Windows example:

call "C:Program FilesIBMWebSphere MQbinamqsput" CAPA.TO.APPB.
SENDQ.REMOTE QMA < QMA_TEST1.TXT

Batch file—UNIX example:

"/opt/mqm/samp/bin/amqsput" CAPA.TO.APPB.SENDQ.REMOTE
QMA < QMA_TEST1.TXT

Where the QMA_TEST1.TXT fle contains the message we want to send. Once we have put a message onto the Send Queue, we need to be able to retrieve it.

To retrieve a message from a Queue(amqsget)

The amqsget utility can be invoked from the command line or from within a batch program. The utility takes 15 seconds to run. We need to specify the Receive Queue that we want to read from and the Queue Manager that the queue belongs to:

$ amqsget <Queue> <QM name>

As example of the command is shown here:

$ amqsget CAPA.TO.APPB.RECVQ QMB

If we have correctly set up all the queues, and the Listeners and Channels are running, then when we issue the preceding command, we should see the message we put onto the Send Queue.

We can put the amqsget command into a batch fle, as shown next:

Batch file—Windows example:

@ECHO This takes 15 seconds to run
call "C:Program FilesIBMWebSphere MQbinamqsget" CAPA.TO.APPB.
RECVQ QMB
@ECHO You should see: test1

Batch file—UNIX example:

echo This takes 15 seconds to run
"/opt/mqm/samp/bin/amqsget" CAPA.TO.APPB.RECVQ QMB
echo You should see: test1

Using these examples and putting messages onto the queues in a unidirectional scenario, then the “get” message batch fle for QMA (SYSA_QMA_TESTG_UNI_BA.BAT) contains:

@ECHO This takes 15 seconds to run
call "C:Program FilesIBMWebSphere MQbinamqsget" CAPA.ADMINQ QMA
@ECHO You should see: test2

From CLP-A, run the fle as:

$ SYSA_QMA_TESTG_UNI_BA.BAT

The “get” message batch file for QMB (SYSB_QMB_TESTG_UNI_AB.BAT) contains:

@ECHO This takes 15 seconds to run
call "C:Program FilesIBMWebSphere MQbinamqsget" CAPA.TO.APPB.
RECVQ QMB
@ECHO You should see: test1

From CLP-B, run the file as:

$ SYSB_QMB_TESTG_UNI_AB.BAT

To browse a message on a Queue

It is useful to be able to browse a queue, especially when setting up Event Publishing. There are three ways to browse the messages on a Local Queue. We can use the rfhutil utility, or the amqsbcg sample program, both of which are WebSphere MQ entities, or we can use the asnqmfmt Q replication command.

  • Using the WebSphere MQ rfhutil utility: The rfhutil utility is part of the WebSphere MQ support pack available to download from the web—to find the current download website, simply type rfhutil into an internet search engine. The installation is very simple—unzip the file and run the rfhutil.exe file.
  • Using the WebSphere MQ amqsbcg sample program: The amqsbcg sample program displays messages including message descriptors.

    $ amqsbcg CAPA.TO.APPB.RECVQ QMB

LEAVE A REPLY

Please enter your comment!
Please enter your name here