Sun Java System Message Queue 4.3 Developer's Guide for C Clients

MQReceiveMessageWithTimeout

The MQReceiveMessageWithTimeout function passes a handle back to a message delivered to the specified consumer if a message is available within the specified amount of time.


MQReceiveMessageWithTimeout
											(const MQConsumerHandle consumerHandle,
											 MQInt32 timeoutMilliseconds,
											 MQMessageHandle * messageHandle);

Return Value

MQStatus. See the MQStatusIsError() function for more information.

Parameters

consumerHandle

The handle to the message consumer. This handle is passed back to you when you create a synchronous message consumer.

timeoutMilliseconds

The number of milliseconds to wait for a message to arrive.

messageHandle

Output parameter for the handle to the message to be received. You are responsible for freeing the message handle when you are done by calling the MQFreeMessage() function.

This function can only be called if the session is created with receive mode MQ_SESSION_SYNC_RECEIVE. The MQReceiveMessageWithTimeout() function passes a handle back to you in the messageHandle parameter if a message arrives for the consumer specified by the consumerHandle parameter in the amount of time specified by the timoutMilliseconds parameter. If no message arrives within the specified amount of time, the function returns an error.

When you create a session, you specify one of several acknowledge modes for that session; these are described in Acknowledge Modes. If you specify MQ_CLIENT_ACKNOWLEDGE as the acknowledge mode for the session, you must explicitly call the MQAcknowledgeMessages function to acknowledge messages that you have received. For more information, see the description of the function MQAcknowledgeMessages().

You can use the MQReceiveMessageWait() function to block while waiting for a message to arrive. You can use the MQReceiveMessageNoWait() function if you do not want to wait for the message to arrive.

Common Errors

MQ_NOT_SYNC_RECEIVE_MODE
MQ_CONCURRENT_ACCESS
MQ_TIMEOUT_EXPIRED
MQ_CONSUMER_CLOSED
MQ_SESSION_CLOSED
MQ_BROKER_CONNECTION_CLOSED
MQ_THREAD_OUTSIDE_XA_TRANSACTION
MQ_XA_SESSION_NO_TRANSATION