Receives a message from a queue.
You can call this operation to receive a message from a queue. After a message is
received, the message changes to the Inactive state. The message remains in the Inactive
state within the period that is specified by the
VisibilityTimeout parameter of the queue. For more information about the VisibilityTimeout parameter,
During the period that is specified by the
VisibilityTimeout parameter, you must call the DeleteMessage operation to delete the message. Otherwise,
the message changes to the Active state and can be consumed again after the specified
Each request consists of the following parts:
- Request line
GET /queues/$queueName/messages? waitseconds=10 HTTP/1.1
- Operation-specific URI parameter
Parameter Required Description waitseconds No The maximum period for which the request waits if no message is available in the queue. Unit: seconds.Note
- If you specify the waitseconds parameter for the ReceiveMessage operation and no message is available in the queue, the request waits for the specified period. If you do not specify the waitseconds parameter, the system uses the PollingWaitSeconds parameter that is specified for the queue. For more information about the PollingWaitSeconds parameter, see CreateQueue.
- We recommend that you reduce the number of concurrent long polling requests. MNS determines the maximum number of concurrent long polling requests based on the number of requests, the waiting period of requests, and the number of IP addresses. If the limit is exceeded, MNS does not hold the request and returns the 404MessageNotExist error. In this case, you are charged based on the number of requests. To avoid unnecessary costs, you can submit a ticket to increase the quota.
- Operation-specific request headers
- Request Body
Each response consists of the following parts:
- HTTP Status Code
HTTP/1.1 200 OK
- Operation-specific response headers
- 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. The message ID is unique in the queue. ReceiptHandle The receipt handle that was generated after the message was consumed. You can use the receipt handle of the message to modify or delete the message that 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 hash of the message body. EnqueueTime The time when the message was sent to the queue. The value is a timestamp that follows the UNIX time format. It is the number of milliseconds that have elapsed since 00:00:00 Thursday, January 1, 1970. NextVisibleTime The next time when the message can be consumed. The value is a timestamp that follows the UNIX time format. It is the number of milliseconds that have elapsed since 00:00:00 Thursday, January 1, 1970. FirstDequeueTime The first time when the message was consumed. The value is a timestamp that follows the UNIX time format. It is the number of milliseconds that have elapsed since 00:00:00 Thursday, January 1, 1970. DequeueCount The total number of times for which the message was consumed. Priority The priority of the message.
GET /queues/$queueName/messages 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 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"? > <Message xmlns="http://mns.aliyuncs.com/doc/v1/"> <MessageId>5F290C926D472878-2-14D9529A8FA-20000****</MessageId> <ReceiptHandle>1-ODU4OTkzNDU5My0xNDMyNzI3ODI3LTItOA==</ReceiptHandle> <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6****</MessageBodyMD5> <MessageBody>This is a test message</MessageBody> <EnqueueTime>1250700979248</EnqueueTime> <NextVisibleTime>1250700799348</NextVisibleTime> <FirstDequeueTime>1250700779318</FirstDequeueTime > <DequeueCount>1</DequeueCount > <Priority>8</Priority> </Message>
|Error code||Error message||HTTP status code|
|QueueNotExist||The queue name you provided is not exist.||404|
|MessageNotExist||Message not exist.||404|