The Batch Asynchronous Consumption sample on z/OS

The CSQ4BCS1 sample program is delivered in C, it demonstrates the use of MQCB and MQCTL to consume messages from multiple queues asynchronously.

The Asynchronous Consumption samples run in the batch environment. See Other samples for the batch applications.

There is also a COBOL sample which runs in the CICS environment, see The CICS Asynchronous Consumption and Publish/Subscribe sample on z/OS.

The applications use these MQI calls:

This topic also provided information about the following headings:


Running the CSQ4BCS1 sample

This sample program follows the following syntax:

CSQ4BCS1 -mQueue Manager Name-0Open options-tRun time Queue name1 Notes:

  • 1 A maximum of 10 queues are supported by this sample. Provide more than one queue name in order to read messages from multiple queues.

There is a sample JCL to run this program, it resides in CSQ4BCSC.


Design of the Batch Asynchronous Consumption sample program

The sample shows how to read messages from multiple queues in the order of their arrival. This would require more code using synchronous MQGET. With asynchronous consumption, no polling is required, and thread and storage management is performed by IBM MQ . In the sample program, errors are written to the console.

The sample code has the following steps:
  1. Define the single message consumption callback function.
    void MessageConsumer(MQHCONN   hConn,
    MQMD  * pMsgDesc,
    MQGMO  * pGetMsgOpts,
    MQBYTE * Buffer,
    MQCBC  * pContext)
    { ... }
    
  2. Connect to the queue manager.
    MQCONN(QMName,&Hcon,&CompCode,&CReason);
    
  3. Open the input queues, and associate each queue with the MessageConsumer callback function.
    MQOPEN(Hcon,&od,O_options,&Hobj,&OpenCode,&Reason);
    cbd.CallbackFunction = MessageConsumer;
    MQCB(Hcon,MQOP_REGISTER,&cbd,Hobj,&md,&gmo,&CompCode,&Reason);
    

    cbd.CallbackFunction does not need to be set for each queue; it is an input-only field. We can associate a different callback function with each queue.

  4. Start consumption of the messages.
    MQCTL(Hcon,MQOP_START,&ctlo,&CompCode,&Reason);
    
  5. Wait for the user to press Enter, then stop consumption of messages.
    MQCTL(Hcon,MQOP_STOP,&ctlo,&CompCode,&Reason);
    
  6. Finally, disconnect from the queue manager.
    MQDISC(&Hcon,&CompCode,&Reason);
    

Parent topic: Use the sample programs for z/OS