调用BatchDeleteMessage接口批量删除队列中的消息。

授权信息

默认仅限阿里云账号使用本接口,RAM用户只有在被授予了相关API操作权限后方可使用。本接口的授权信息如下表所示。更多信息,请参见授权策略和示例

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

使用说明

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

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

请求消息

请求消息由请求行、HTTP头和消息体三部分组成:

  • 请求行

    DELETE /queues/$queueName/messages HTTP/1.1

  • 特有Request Header

    无。

  • Request Body

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

返回消息

返回消息由返回状态行,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+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>            

返回示例:

  • 正常删除所有消息
        HTTP/1.1 204 No Content
        x-mns-request-id:512B2A634403E52B1956****
        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: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>                    

错误码

错误码 错误信息 HTTP状态码 描述内容
InvalidArgument The value of Element should between Low and High seconds/bytes. 400 参数值非法,请根据提示调整。
ReceiptHandleError The receipt handle you provide is not valid. 400 请求参数不合法。
QueueNotExist The queue name you provided is not exist. 404 队列不存在,请先创建队列。
MessageNotExist The receipt handle you provided has expired. 404 消费消息过慢导致消息重新回到队列生成新的ReceiptHandle,之前的ReceiptHandle失效。请加快消费速度或者增加队列的不可见时间。