The Browse sample programs

 


The Browse sample programs browse messages on a queue using the MQGET call. See Features demonstrated in the sample programs for the names of these programs.

 

OS/2, UNIX systems, Compaq OpenVMS Alpha, and Windows systems

The C version of the program takes 2 parameters

  1. The name of the source queue (necessary)

  2. The name of the queue manager (optional)

If a queue manager is not specified, it will connect to the default one. For example, enter one of the following:

amqsgbr myqueue qmanagername

amqsgbrc myqueue qmanagername

amq0gbr0 myqueue

where myqueue is the name of the queue that the messages will be viewed from, and qmanagername is the queue manager that owns myqueue.

If you omit the qmanagername, when running the C sample, it will assume that the default queue manager owns the queue.

The COBOL version does not have any parameters. It connects to the default queue manager and when you run it you are prompted:

Please enter the name of the target queue

Only the first 50 characters of each message are displayed, followed by - - - truncated when this is the case.

 

OS/400

Each program retrieves copies of all the messages on the queue you specify when you call the program; the messages remain on the queue. You could use the supplied queue SYSTEM.SAMPLE.LOCAL; run the Put sample program first to put some messages on the queue. You could use the queue SYSTEM.SAMPLE.ALIAS, which is an alias name for the same local queue. The program continues until it reaches the end of the queue or an MQI call fails.

The C samples allow for specification of queue manager name, generally as the second parameter, in a similar fashion to the Windows systems samples. For example:

CALL PGM(QMQM/AMQSTRG4) PARM('SYSTEM.SAMPLE.TRIGGER' 'QM01')

If a queue manager is not specified, it will connect to the default one. This is also relevant to the RPG samples. However, with the RPG samples supply a queue manager name rather than allowing it to default.

 

Design of the Browse sample program

The program opens the target queue using the MQOPEN call with the MQOO_BROWSE option. If it cannot open the queue, the program outputs an error message containing the reason code returned by the MQOPEN call.

For each message on the queue, the program uses the MQGET call to copy the message from the queue, then displays the data contained in the message. The MQGET call uses these options:

MQGMO_BROWSE_NEXT
After the MQOPEN call, the browse cursor is positioned logically before the first message in the queue, so this option causes the first message to be returned when the call is first made.

MQGMO_NO_WAIT
The program does not wait if there are no messages on the queue.

MQGMO_ACCEPT_TRUNCATED_MSG
The MQGET call specifies a buffer of fixed size. If a message is longer than this buffer, the program displays the truncated message, together with a warning that the message has been truncated.

The program demonstrates how clear the MsgId and CorrelId fields of the MQMD structure after each MQGET call, because the call sets these fields to the values contained in the message it retrieves. Clearing these fields means that successive MQGET calls retrieve messages in the order in which the messages are held in the queue.

The program continues to the end of the queue; at this point the MQGET call returns the MQRC_NO_MSG_AVAILABLE reason code and the program displays a warning message. If the MQGET call fails, the program displays an error message that contains the reason code.

The program then closes the queue using the MQCLOSE call.