Communications/Transactions Guide and Reference

Step 5: Getting messages from a queue

Use the AbtMQMessage class to specify the message options. Then you can get the message from the queue using a variety of get... methods.

This example uses the msgId: method of AbtMQMessage to specify the message ID of the message being retrieved. Any messages that do not match the specified message ID will be left on the queue.

| aModelMessage aQueue rc |
 
"Sample App 1: getting two messages with the same msg ids"
CICSTTY cr; show: 'Get messages with 'Msg Duplicate''
                          message ID from the queue.'.
 
"Define the message"
aModelMessage := AbtMQMessage new msgId: 'Msg Duplicate'; length: 100.
 
rc := nil.
[rc isAbtError not]
         whileTrue: [
 
         "Get the message from the queue and verify the call"
         (rc := aQueue getMessageWithModelMessage: aModelMessage)
             isAbtError
                ifTrue: [rc reason = MqrcNoMsgAvailable " 2033 "
                     ifTrue: [CICSTTY cr;
                          show: 'The NoMsgAvailable reason code
                                 is expected for Msg Duplicate.'.]
                     ifFalse: [CICSTTY cr;
                          show: 'No Msg returned, reason code: ',
                                 (rc codesAsString)]]
               ifFalse: [CICSTTY cr;
                     show: 'Message ID is: ', (rc msgId);
                     show: ', Data is: ', (rc contentsAsString)]
               ].
Note:The above example assumes that no background forked process is consuming messages from the queue. This is because sample Application 1 does not start the forked background process.

Sample Application 2 uses the AbtMQMessage class to specify the message options:

| rc anMQConnection |
 
"Sample App 2: simple get using the connection"
(rc := aQueueConnection get) isAbtError
        ifTrue: [rc reason = MqrcNoMsgAvailable " 2033 "
             ifTrue: [CICSTTY cr;
                     show: 'The NoMsgAvailable reason code
                            is expected.'.]
             ifFalse: [CICSTTY cr;
                     show: 'No Msg returned, reason code: ',
                            (rc codesAsString)]]
        "Message received: show some of the values"
        ifFalse: [CICSTTY
             cr; show: 'Message ID is: ', (rc msgId);
             cr; show: 'Data is: ', (rc contentsAsString);
             cr; show: ' putApplName: ', (rc putApplicationName);
             cr; show: ' putApplType: ',
                      (rc putApplicationType printString).].
Note:The above example uses different methods to retrieve messages from those used in Sample Application 1. This is because Sample Application 2 starts a forked background process to consume messages from the queue.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]