MQReadAllXML function

The MQReadAllXML function returns a table containing the messages and message metadata from the WebSphere MQ location specified by receive-service using the quality of service-policy.

Performing this operation does not remove the messages from the queue associated with receive-service. If num-rows is specified, a maximum of num-rows messages is returned. If num-rows is not specified, all of the available messages are returned.

Syntax

Read syntax diagramSkip visual syntax diagramMQReadAllXML (receive-servicereceive-service,service-policynum-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.
service-policy
A string containing the WebSphere MQ Service Policy used to the handling this message. If specified, service-policy refers to a Policy defined in the DB2MQ.MQPOLICY table. A service 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 service-policy is not specified, the default DB2.DEFAULT.POLICY is used. The maximum size of service-policy is 48 bytes.
num-rows
A positive integer containing the maximum number of messages the function returns.

Results

The MQReadAllXML function returns a table containing messages and message metadata as described in the following table.

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 from the queue that are specified by the default service DB2.DEFAULT.SERVICE are read using the default policy DB2.DEFAULT.POLICY. The messages and all the metadata are returned in a table format.

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

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

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

Example 3: The queue that is specified by the default service DB2.DEFAULT.SERVICE is read using the default policy DB2.DEFAULT.POLICY. Only messages with a CORRELID of 1234 are returned. Up to 10 messages are read and returned. All columns are returned.

select * from table (DB2MQ.MQREADALLXML()) t where t.CORRELID = '1234'

Example 4: The messages that are specified by the default service DB2.DEFAULT.SERVICE are read using the default policy DB2.DEFAULT.POLICY. All columns are returned.

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