Deletes multiple messages from a queue.
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 Authorization policies and examples.
| Item | Value |
| API operation | BatchDeleteMessage |
| Action | mns:BatchDeleteMessage |
| Resource | acs:mns:$region:$accountid:/queues/$queueName/messages |
Description
You can call this operation to delete multiple messages from a queue. A maximum of 16 messages can be deleted at a time. The receipt handle of each message that you want to delete must be included in the request.
We recommend that you use this operation in combination with the BatchReceiveMessage operation to improve efficiency. A request that is used to delete multiple messages includes multiple subrequests, and some subrequests may fail. The HTTP status code 204 is returned only if all subrequests succeed. If some subrequests fail, you must check the error message in each response.
Request
A request consists of the following parts:
- Request line
DELETE /queues/$queueName/messages HTTP/1.1 - Operation-specific request headers
None.
- Request body
The request body is in the XML format. The receipt handle of each message that you want to delete must be included in the request.
Response
A response consists of the following parts:
- HTTP status code
HTTP/1.1 204 NoContent - Operation-specific response headers
None.
- Response body
None.
Examples
Sample requests
DELETE /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****
<?xml version="1.0" encoding="UTF-8"?>
<ReceiptHandles xmlns="http://mns.aliyuncs.com/doc/v1/">
<ReceiptHandle>1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
<ReceiptHandle>1-ODU4OTkzNDU5NC0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
<ReceiptHandle>1-ODU4OTkzNDU5NS0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
</ReceiptHandles> Sample responses
- Sample success responses if all messages are deleted
HTTP/1.1 204 No Content x-mns-request-id:512B2A634403E52B1956**** x-mns-version: 2015-06-06 - Sample responses if some messages fail to be deleted
HTTP/1.1 404 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"?> <Errors xmlns="http://mns.aliyuncs.com/doc/v1/"> <Error> <ErrorCode>MessageNotExist</ErrorCode> <ErrorMessage>Message not exist.</ErrorMessage> <ReceiptHandle>1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==</ReceiptHandle> </Error> <Error> <ErrorCode>MessageNotExist</ErrorCode> <ErrorMessage>Message not exist.</ErrorMessage> <ReceiptHandle>1-ODU4OTkzNDU5NC0xNDM1MTk3NjAwLTItNg==</ReceiptHandle> </Error> </Errors>
Error codes
| Error code | HTTP status code | Error message | Description |
|---|---|---|---|
| QueueNotExist | 404 | The queue name you provided does not exist. | The specified queue does not exist. Verify the queue name in the request URI. |
| InvalidArgument | 400 | The value of Element should between Low and High seconds/bytes. | A parameter value is out of the valid range. Check the request parameters against the allowed value ranges. |
| ReceiptHandleError | 400 | The receipt handle you provided is not valid. | The receipt handle has expired because NextVisibleTime has passed, or an outdated handle was used. Consume the message again to get a new receipt handle. |