Queries a message.

Name Value
API operation PeekMessage
RAM policy mns:PeekMessage
Resource acs:mns:$region:$accountid:/queues/$queueName/messages

Description

You can call this operation to query a message. Different from the ReceiveMessage operation, the PeekMessage operation does not change the message status. After you call the PeekMessage operation to view a message, the message remains Active and can still be viewed or consumed. However, if you call the ReceiveMessage operation to consume a message, the status of the message switches to Inactive and cannot be viewed or consumed within the period that is specified by the VisibilityTimeout parameter.

Request

A request consists of the following sections:

  • Request line

    GET /queues/$queueName/messages? peekonly=true HTTP/1.1

  • URI parameters

    peekonly=true: indicates that this request is only used to view a message in the queue and does not change the message status.

  • Exclusive request headers

    None. For information about common request headers, see Common parameters

  • Request body

    N/A

Response

A response consists of the following sections: a status line, HTTP headers, and the response body.

  • HTTP status code

    HTTP/1.1 200 OK

  • Exclusive response headers

    None. For information about common response headers, see Common parameters

  • Response body

    The content format of the response body is XML. A message and the parameters of the message are returned.

    Parameter Description
    MessageId The ID of the message. Message IDs are unique in a queue.
    MessageBody The message content.
    MessageBodyMD5 The MD5 hash of the message content.
    EnqueueTime 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 The first time when 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 The total number of times the message was consumed.
    Priority The priority of the message.

Examples

Sample requests

GET  /queues/$queueName/messages? peekonly=true 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+FIEXAMPLE           

Sample success responses

HTTP/1.1 200 OK
Connection:close
Content-Type=text/xml;charset=utf-8
Content-Length:500
x-mns-request-id:512B2A634403E52B1956133E
x-mns-version: 2015-06-06

<? xml version="1.0" encoding="UTF-8"? >
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
    <MessageId>D6D5F7C9C12D14A4-1-14D953EFC72-200000004</MessageId>
    <MessageBodyMD5>F9360F391579E71CA77BC5D50242FCF4</MessageBodyMD5>
    <MessageBody>This is a test message</MessageBody>
    <EnqueueTime>1250700979248</EnqueueTime>
    <FirstDequeueTime>1250700979348</FirstDequeueTime >
    <DequeueCount>5</DequeueCount>
    <Priority>8<Priority>
</Message>            

Error codes

Error code Error message HTTP status code
QueueNotExist The queue name you provided is not exist. 404
MessageNotExist Message not exist. 404