MQListener examples

The application receives a message, inserts the message into a table, and generates a simple response message.

To simulate a processing failure, the application includes a check constraint on the table that contains the message. The constraint prevents any string that begins with the characters 'fail' from being inserted into the table. If you attempt to insert a message that violates the check constraint, the example application returns an error message and re-queues the failing message to the backout queue.

In this example, the following assumptions are made:
  • MQListener is installed and configured for subsystem DB7A.
  • MQND is the name of IBM® MQ subsystem that is defined. The Queue Manager is running, and the following local queues are defined in the DB7A subsystem:
    • ADMIN_Q : Admin queue
    • BACKOUT_Q : Backout queue
    • IN_Q : Input queue that has a backout queue withthreshold = 3
    • REPLY_Q : Output queue or Reply queue
    • DEADLLETTER_Q : Dead letter queue
  • The person who is running the MQListener daemon has execute permission on the DB2MQLSN plan.
Before you run the MQListener daemon, add the following configuration, named ACFG, to the configuration table by issuing the following command:
db2mqln2 add 
   -ssID DB7A  
   -config ACFG
   -queueManager MQND
   -inputQueue IN_Q
   -procName APROC
   -procSchema TEST
Run the MQListener daemon for two-phase commit for configuration ACFG by issuing the following command:
db2mqln2 run 
   -ssID DB7A  
   -config ACFG
   -adminQueue ADMIN_Q
   -adminQMgr MQND
   -numMessagesCommit 1
   -timeRestart 60

The following examples show how to use MQListener to send a simple message and then inspect the results of the message in the IBM MQ queue manager and the database. The examples include queries to determine if the input queue contains a message or to determine if a record is placed in the table by the stored procedure.

MQListener example 1: Running a simple application:
  1. Start with a clean database table by issuing the following SQL statement:
    delete from PROCTABLE
  2. Send a datagram to the input queue, 'IN_Q', with the message as 'sample message'. Refer to WebSphere® MQ sample CSQ4BCK1 to send a message to the queue. Specify the MsgType option for 'Message Descriptor' as 'MQMT_DATAGRAM'.
  3. Query the table by using the following statement to verify that the sample message is inserted:
    select * from PROCTABLE
  4. Display the number of messages that remain on the input queue to verify that the message has been removed. Issue the following command from a z/OS® console:
    /-MQND display queue('In_Q') curdepth
MQListener example 2: Sending requests to the input queue and inspecting the reply:
  1. Start with a clean database table by issuing the following SQL statement:
    delete from PROCTABLE
  2. Send a request to the input queue, 'IN_Q', with the message as 'another sample message'. Refer to IBM MQ sample CSQ4BCK1 to send a message to the queue. Specify the MsgType option for 'Message Descriptor' as 'MQMT_REQUEST' and the queue name for ReplytoQ option.
  3. Query the table by using the following statement to verify that the sample message is inserted:
    select * from PROCTABLE
  4. Display the number of messages that remain on the input queue to verify that the message has been removed. Issue the following command from a z/OS console:
    /-MQND display queue('In_Q') curdepth
  5. Look at the ReplytoQ name that you specified when you sent the request message for the reply by using the IBM MQ sample program CSQ4BCJ1. Verify that the string 'OK' is generated by the stored procedure.
MQListener example 3: Testing an unsuccessful insert operation: If you send a message that starts with the string 'fail', the constraint in the table definition is violated, and the stored procedure fails.
  1. Start with a clean database table by issuing the following SQL statement:
    delete from PROCTABLE
  2. Send a request to the input queue, 'IN_Q', with the message as 'failing sample message'. Refer to IBM MQ sample CSQ4BCK1 to send a message to the queue. Specify the MsgType option for 'Message Descriptor' as 'MQMT_REQUEST' and the queue name for ReplytoQ option.
  3. Query the table by using the following statement to verify that the sample message is not inserted:
    select * from PROCTABLE
  4. Display the number of messages that remain on the input queue to verify that the message has been removed. Issue the following command from a z/OS console:
    /-MQND display queue('In_Q') curdepth
  5. Look at the Backout queue and find the original message by using the WebSphere MQ sample program CSQ4BCJ1.

Note: In this example, if a request message with added options for 'exception report' is sent (the Report option is specified for 'Message Descriptor'), an exception report is sent to the reply queue and the original message is sent to the deadletter queue.