Receives multiple messages from a queue.
Name | Value |
---|---|
API | BatchReceiveMessage |
Action | mns:BatchReceiveMessage |
Resource | acs:mns:$region:$accountid:/queues/$queueName/messages |
Description
You can call this operation to receive a maximum of 16 messages from a queue. After
the messages are received, the messages enter the Inactive state. The messages remain
Inactive within the period that is specified by the VisibilityTimeout
parameter. For more information about the VisibilityTimeout parameter, see CreateQueue.
During the period that is specified by the VisibilityTimeout
parameter, you can consume the messages and call the DeleteMessage operation to delete
the messages. Otherwise, the messages change to the Active state and can be consumed
again after the specified period.
Request
Each request consists of the following parts:
- Request line
GET /queues/$queueName/messages? numOfMessages=16&waitseconds=10 HTTP/1.1
- Operation-specific URI parameter
Parameter Required Description numOfMessages Yes The maximum number of messages that can be received. waitseconds No The maximum period for which the request waits if no message is available in the queue. Unit: seconds.
waitseconds
parameter when you call the BatchReceiveMessage operation, the request holds for
the specified period. If no message is available during the specified period, the
long-polling request times out.
If you do not specify the waitseconds
parameter when you call the BatchReceiveMessage operation, the PollingWaitSeconds
parameter that is specified for the queue is used by default. For more information,
see CreateQueue.
- Operation-specific request headers
None. For more information about common request headers, see Common parameters.
- Request Body
None.
Response
Each response consists of the following parts:
- HTTP Status Code
HTTP/1.1 200 OK
- Operation-specific response headers
None. For more information about common response headers, see Common parameters.
- Response Body
The response body is in the XML format. The body and parameters of multiple messages are returned.
Parameter Description MessageId The ID of the message. The message ID is unique in the queue. ReceiptHandle The receipt handle that was generated when the message was received. 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 only 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 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 that the message was consumed. Priority The priority of the message.
Examples
Sample requests
GET /queues/$queueName/messages? 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+FIEXAMPLE
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"? >
<Messages xmlns="http://mns.aliyuncs.com/doc/v1/">
<Message>
<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>
<Message>
<ReceiptHandle>1-ODU4OTkzNDU5My0xNDMyNzI3MjQwLTEtOA==</ReceiptHandle>
<MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
<MessageBody>This is a test message</MessageBody>
<EnqueueTime>1250700979252</EnqueueTime>
<NextVisibleTime>1250700799350</NextVisibleTime>
<FirstDequeueTime>1250700779330</FirstDequeueTime >
<DequeueCount>1</DequeueCount>
<Priority>8</Priority>
</Message>
</Messages>
Special Error
Error code | Error message | HTTP status code |
---|---|---|
QueueNotExist | The queue name you provided is not exist. | 404 |
MessageNotExist | Message not exist. | 404 |