使用BatchDeleteMessage接口来批量删除队列多条消息。

Name Value
API BatchDeleteMessage
RAM授权操作 mns:BatchDeleteMessage
资源 acs:mns:$region:$accountid:/queues/$queueName/messages

描述

该接口用于批量删除队列多条消息,最多可以删除16条消息,每条消息需要传入相应的ReceiptHandle。

建议此接口与BatchReceiveMessage接口搭配使用,效率会更高。批量操作的结果可能同时包含成功和失败的子请求。只有全部子请求都成功时,HTTP状态码才是204。当部分失败发生时,需检查响应中每个消息的错误信息。

Request

Request的构造主要由以下几个部分组成:

  • 请求行

    DELETE /queues/$queueName/messages HTTP/1.1

  • 特有Request Header

    无,请参见公共参数

  • Request Body

    Request Body为XML格式,其中包含多条消息的ReceiptHandle。

Response

返回消息由返回状态行,HTTP头和消息体三部分组成。

  • HTTP Status Code

    HTTP/1.1 204 NoContent

  • 特有Response Header

    无,请参见公共参数

  • Response Body

示例

请求示例:

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+FIEXAMPLE

<?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>            

返回示例:

  • 正常删除所有消息
        HTTP/1.1 204 No Content
        x-mns-request-id:512B2A634403E52B1956133E
        x-mns-version: 2015-06-06                  
  • 部分消息删除失败
        HTTP/1.1 404
        Connection:close
        Content-Type=text/xml;charset=utf-8
        Content-Length:500
        x-mns-request-id:512B2A634403E52B1956133E
        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>                    

Special Error

错误码 错误信息 状态码
QueueNotExist The queue name you provided is not exist. 404
InvalidArgument The value of Element should between Low and High seconds/bytes. 400
ReceiptHandleError The receipt handle you provide is not valid. 400