Queries multiple messages.
Authorization
By default, only Alibaba Cloud accounts can call this operation. RAM users can call this operation only after these RAM users are granted related permissions. The following table describes the authorization information of this operation. For more information, see Permission policies and examples.
Item | Value |
API operation | BatchPeekMessage |
Action | mns:BatchPeekMessage |
Resource | acs:mns:$region:$accountid:/queues/$queueName/messages |
Description
You can call this operation to query a maximum of 16 messages at a time.
Different from the BatchReceiveMessage operation, the BatchPeekMessage operation does not change the statuses of the messages. After you call the BatchPeekMessage operation to view messages, the messages remain in the Active state and can still be viewed or consumed. However, if you call the BatchReceiveMessage operation to receive messages, the messages enter the Inactive state and cannot be viewed or consumed within the period specified by the VisibilityTimeout
parameter.
Request
A request consists of the following parts:
Request line
GET /queues/$queueName/messages?peekonly=true&numOfMessages=16 HTTP/1.1
Operation-specific URI parameter
Parameter
Type
Required
Example
Description
peekonly
Boolean
Yes
true
Specifies that this request is used only to view messages in the queue and does not change the statuses of the messages. The value is fixed to true.
numOfMessages
Integer
No
16
The maximum number of messages that can be viewed at a time.
Operation-specific request headers
None.
Request body
None.
Response
A response consists of the following parts:
HTTP status code
HTTP/1.1 200 OK
Operation-specific response headers
None.
Response body
The response body is in the XML format. The bodies and parameters of multiple messages are returned.
Parameter
Type
Example
Description
MessageId
String
D6D5F7C9C12D14A4-1-14D953EFC72-20000****
The ID of the message. The message ID is unique in the queue.
MessageBody
String
This is a test message.
The body of the message.
MessageBodyMD5
String
F9360F391579E71CA77BC5D50242****
The MD5 hash of the message body.
EnqueueTime
Long
1250700979248
The time when the message was sent to the queue. This value is a UNIX timestamp representing the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.
FirstDequeueTime
Long
1250700979348
The first time the message was consumed. This value is a UNIX timestamp representing the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC. If the value of the
DequeueCount
parameter is 0, the value of the FirstDequeueTime parameter is the same as the value of the EnqueueTime parameter.DequeueCount
Integer
5
The total number of times for which the message was consumed.
Examples
Sample requests
GET /queues/$queueName/messages?peekonly=true&numOfMessages=16 HTTP/1.1
Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
Date: Wed, 28 May 2012 22:32:00 GMT
x-mns-version: 2015-06-06
Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXA****
Sample success responses
HTTP/1.1 200 OK
Connection:close
Content-Type=text/xml;charset=utf-8
Content-Length:500
x-mns-request-id:512B2A634403E52B1956****
x-mns-version: 2015-06-06
<?xml version="1.0" encoding="UTF-8"?>
<Messages xmlns="http://mns.aliyuncs.com/doc/v1/">
<Message>
<MessageId>D6D5F7C9C12D14A4-1-14D953EFC72-20000****</MessageId>
<MessageBodyMD5>F9360F391579E71CA77BC5D50242****</MessageBodyMD5>
<MessageBody>This is a test message.</MessageBody>
<EnqueueTime>1250700979248</EnqueueTime>
<FirstDequeueTime>1250700979348</FirstDequeueTime >
<DequeueCount>5</DequeueCount>
<Priority>8<Priority>
</Message>
<Message>
<MessageId>D6D5F7C9C12D14A4-1-14D953EFC72-20000****</MessageId>
<MessageBodyMD5>F9360F391579E71CA77BC5D50242****</MessageBodyMD5>
<MessageBody>This is a test message.</MessageBody>
<EnqueueTime>1250700979250</EnqueueTime>
<FirstDequeueTime>1250700979352</FirstDequeueTime >
<DequeueCount>5</DequeueCount>
<Priority>8<Priority>
</Message>
</Messages>
Error codes
Error code | Error message | HTTP status code | Description |
QueueNotExist | The queue name you provided is not exist. | 404 | The error message returned because the specified queue does not exist. Create a queue. |
MessageNotExist | Message not exist. | 404 | The error message returned because no visible message exists in the queue. |