The Batch Asynchronous Consumption sample
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.
- MQCONN
- MQOPEN
- MQCLOSE
- MQDISC
- MQCB
- MQCTL
Running the CSQ4BCS1 sample
This sample program follows the following syntax:
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.
- Define the single message consumption callback function.
void MessageConsumer(MQHCONN hConn, MQMD * pMsgDesc, MQGMO * pGetMsgOpts, MQBYTE * Buffer, MQCBC * pContext) { ... }
- Connect to the queue manager.
MQCONN(QMName,&Hcon,&CompCode,&CReason);
- 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. You can associate a different callback function with each queue. - Start consumption of the messages.
MQCTL(Hcon,MQOP_START,&ctlo,&CompCode,&Reason);
- Wait for the user to press Enter, then stop consumption of messages.
MQCTL(Hcon,MQOP_STOP,&ctlo,&CompCode,&Reason);
- Finally, disconnect from the queue manager.
MQDISC(&Hcon,&CompCode,&Reason);