Get messages from a queue
Use this information to learn about getting messages from a queue.
We can get messages from a queue in two ways:
We can remove a message from the queue so that other programs can no longer see it.
We can copy a message, leaving the original message on the queue. This is known as browsing. We can remove the message once we have browsed it.
In both cases, we use the MQGET call, but first our application must be connected to the queue manager, and you must use the MQOPEN call to open the queue (for input, browse, or both). These operations are described in Connecting to and disconnecting from a queue manager and Opening and closing objects .
When we have opened the queue, we can use the MQGET call repeatedly to browse or remove messages on the same queue. Call MQCLOSE when we have finished getting all the messages that you want from the queue.
Use the following links to find out more about getting messages from a queue:
Get messages from a queue using the MQGET call
The MQGET call gets a message from an open local queue. It cannot get a message from a queue on another system.
The order in which messages are retrieved from a queue
We can control the order in which you retrieve messages from a queue. This section looks at the options.
Get a particular message
There are a number of ways of getting a particular message from a queue. These are: selecting on the MsgId and CorrelId, selecting on the GroupId, MsgSeqNumber and Offset, and selecting on the MsgToken. We can also use a selection string when you open the queue.
Improving performance of non-persistent messages
When a client requires a message from a server, it sends a request to the server. It sends a separate request for each of the messages it consumes. To improve the performance of a client consuming non persistent messages by avoiding having to send these request messages, a client can be configured to use read ahead. Read ahead allows messages to be sent to a client without an application having to request them.
Type of index
The queue attribute, IndexType, specifies the type of index that the queue manager maintains to increase the speed of MQGET operations on the queue.
Handling messages greater than 4 MB long
Messages can be too large for the application, queue, or queue manager. Depending on the environment, IBM MQ provides a number of ways of dealing with messages that are longer than 4 MB.
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.
Signaling
Signaling is supported only on IBM MQ for z/OS.
Skipping backout
We can prevent an application program from entering an MQGET-error-backout loop by specifying the MQGMO_MARK_SKIP_BACKOUT option on the MQGET call.
Application data conversion
When necessary, MCAs convert the message descriptor and header data into the required character set and encoding. Either end of the link (that is, the local MCA or the remote MCA) can do the conversion.
Browsing messages on a queue
Use this information to find out about browsing messages on a queue using the MQGET call.
Some cases where the MQGET call fails
If certain attributes of a queue are changed using the FORCE option on a command between issuing an MQOPEN and an MQGET call, the MQGET call fails and returns the MQRC_OBJECT_CHANGED reason code.
Parent topic: Writing a procedural application for queuing
Related concepts