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 Permission 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 Error message HTTP status code Description
InvalidArgument The value of Element should between Low and High seconds/bytes. 400 The error message returned because the value of the parameter is invalid. You must specify a valid value as prompted.
ReceiptHandleError The receipt handle you provide is not valid. 400 The error message returned because the ReceiptHandle parameter is invalid.
QueueNotExist The queue name you provided is not exist. 404 The error message returned because the specified queue does not exist. Create a queue.
MessageNotExist The receipt handle you provided has expired. 404 The error message returned because you have not consumed a message within the invisibility period and the receipt handle of the message has expired. Consume messages within the invisibility period or specify a longer invisibility period.