Consumes a message from a queue. After a message is received, the ReceiveMessage operation changes the status of the message to Inactive. The message remains in the Inactive state for a period of time that is specified by the VisibilityTimeout parameter of the queue. After the period ends, the status of the message changes to Active and the message can be consumed again. If you need to delete the message after it is consumed, you must call the DeleteMessage operation.

Request

A request consists of the following parts:

  • Request line

    GET /$queueName/messages? waitseconds=10 HTTP/1.1

  • Operation-specific URI parameter
    Parameter Description Required
    waitseconds The maximum length of time for which this ReceiveMessage request waits for a message to arrive. Unit: seconds. No
    Note If you provide the waitseconds parameter in a ReceiveMessage request and no messages exists in the queue, the ReceiveMessage request waits for a period of time that is specified by this parameter. If you do not provide this parameter, the value that is specified by the PollingWaitSeconds parameter of the queue is used.
  • Operation-specific request headers

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

  • Request body

    None .

Response

A response consists of a status line, HTTP headers, and a response body.

  • HTTP status code

    HTTP/1.1 200 OK

  • Operation-specific response headers

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

  • Response body

    The response is in the XML format. It contains the message body and other parameters of the message.

    Parameter Description
    MessageId The ID of the message. It is unique in the queue.
    ReceiptHandle The temporary receipt handle. You must specify the receipt handle if you need to delete or modify the message when it is in the Inactive state. The receipt handle is valid before the time that is specified by the NextVisibleTime parameter.
    MessageBody The body of the message.
    MessageBodyMD5 The MD5 digest of the message body.
    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.
    NextVisibleTime The time when the message can be consumed again. 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 time when the message was consumed for the first time. 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.
    DequeueCount The number of times that the message has been consumed.
    Priority The priority of the 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
  • Sample requests
    GET  /$queueName/messages HTTP/1.1
        Host: $AccountId.mqs-cn-hangzhou.aliyuncs.com
        Date: Wed, 28 May 2012 22:32:00 GMT
        x-mqs-version: 2014-07-08
        Authorization: MQS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE            
  • Sample responses
        HTTP/1.1 200 OK
        Connection:close
        Content-Type=text/xml;charset=utf-8
        Content-Length:500
        x-mqs-request-id:512B2A634403E52B1956133E 
        x-mqs-version:2015-06-06
    
        <? xml version="1.0” encoding=”UTF-8” ? >
        <Message xmlns=”http://mqs.aliyuncs.com/doc/v1/”>
            <MessageId>5F290C926D472878-2-14D9529A8FA-200000001</MessageId>
            <ReceiptHandle>1-ODU4OTkzNDU5My0xNDMyNzI3ODI3LTItOA==</ReceiptHandle>
            <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
            <MessageBody>This is a test message</MessageBody>
            <EnqueueTime>1250700979248</EnqueueTime>
            <NextVisibleTime>1250700799348</NextVisibleTime>
            <FirstDequeueTime>1250700779318</FirstDequeueTime >
            <DequeueCount>1</DequeueCount >
            <Priority>8</Priority>
        </Message>