Waiting for messages

 

If you want a program to wait until a message arrives on a queue, specify the MQGMO_WAIT option in the Options field of the MQGMO structure. Use the WaitInterval field of the MQGMO structure to specify the maximum time (in milliseconds) that you want an MQGET call to wait for a message to arrive on a queue.

If the message does not arrive within this time, the MQGET call completes with the MQRC_NO_MSG_AVAILABLE reason code.

We can specify an unlimited wait interval using the constant MQWI_UNLIMITED in the WaitInterval field. However, events outside your control could cause your program to wait for a long time, so use this constant with caution. IMS applications must not specify an unlimited wait interval because this would prevent the IMS system terminating. (When IMS terminates, it requires all dependent regions to end.) Instead, IMS applications can specify a finite wait interval; then, if the call completes without retrieving a message after that interval, issue another MQGET call with the wait option.

If more than one program is waiting on the same shared queue to remove a message, only one program is activated by a message arriving. However, if more than one program is waiting to browse a message, all the programs can be activated. For more information, see the description of the Options field of the MQGMO structure in the Application Programming Reference.

If the state of the queue or the queue manager changes before the wait interval expires, the following actions occur:

If you want your application to wait on more than one queue, use the signal facility of WebSphere MQ for z/OS (see Signaling). For more information about the circumstances in which these actions occur, see the Application Programming Reference.

 

Parent topic:

Writing a WebSphere MQ application


fg12760_