MQReceiveAllXML function

The MQReceiveAllXML function removes messages associated with receive-service from the queue.

If the correl-id is specified, only those messages with a matching correlation identifier are returned. If correl-id is not specified, the message at the head of the queue is returned. If num-rows is specified, a maximum of num-rows messages is returned. If num-rows is not specified, all available messages are returned.

Syntax

Read syntax diagramSkip visual syntax diagramMQReceiveAllXML ( receive-servicereceive-service,receive-policyreceive-service,receive-policycoreel-id num-rows )

Parameters

receive-service
A string containing the logical WebSphere® MQ destination from where the message will be received. If specified, receive-service must refer to a service point defined in the DB2MQ.MQSERVICE table. A service point is a logical end-point from where a message is sent or received. Service point definitions include the name of the WebSphere MQ Queue Manager and Queue. If receive-service is not specified, the DB2®.DEFAULT.SERVICE is used. The maximum size of receive-service is 48 bytes.
receive-policy
A string containing the MQSeries receive policy used to handle this message. If specified, receive-policy must refer to a policy defined in the DB2MQ.MQPOLICY table. A receive policy defines a set of quality of service options that should be applied to this messaging operation. These options include message priority and message persistence. If receive-policy is not specified, the default DB2.DEFAULT.POLICY is used. The maximum size of receive-policy is 48 bytes.
correl-id
An optional string containing a correlation identifier associated with this message. The correl-id is often specified in request and reply scenarios to associate requests with replies. If not specified, no correlation ID is sent. The maximum size of correl-id is 24 bytes.
num-rows
A positive integer that contains the maximum number of messages returned by the function.

Results

When a table of messages is successfully received from the queue, MQRECEIVEXML returns XML. A NULL is returned when no messages are available. The messages are returned as a table of messages with metadata.

Table 1. Result set table
Column name Data type Description
MSG XML The contents of the WebSphere MQ message. You can specify the length of XML data when you enable the MQ XML user-defined functions.
CORRELID VARCHAR(24) A correlation ID that you can use to relate to messages.
TOPIC VARCHAR(40) The topic the message was published with, if available.
QNAME VARCHAR(48) The name of the queue where the message was received.
MSGID VARCHAR(24) The unique identifier that WebSphere MQ assigns for a message.
MSGFORMAT VARCHAR(8) The format of the message that WebSphere MQ defines. Typical strings have a format of MQSTR.

Examples

Example 1: All the messages received from the queue are specified by the default service (DB2.DEFAULT.SERVICE) using the default policy (DB2.DEFAULT.POLICY). The messages and all the metadata are returned as a table.

select * from table (DB2MQ.MQRECEIVEALLXML()) t

Example 2: All the messages are received from the head of the queue and are specified by the service MYSERVICE using the default policy (DB2.DEFAULT.POLICY). Only the MSG and CORRELID columns are returned. The messages are in table format, wherein you can select the fields that you want.

select t.MSG, t.CORRELID from table (DB2MQ.MQRECEIVEALLXML('MYSERVICE')) t

Example 3: All the messages received from the head of the queue are specified by the service MYSERVICE using the policy MYPOLICY that match the ID '1234'. Only the MSG and CORRELID columns are returned.

select t.MSG, t.CORRELID from table (DB2MQ.MQRECEIVEALLXML('MYSERVICE','MYPOLICY','1234')) t

Example 4: The first 10 messages are received from the head of the queue and specified by the default service (DB2.DEFAULT.SERVICE) using the default policy (DB2.DEFAULT.POLICY) . All columns are returned.

select * from table (DB2MQ.MQRECEIVEALLXML(10)) t