All Products
Search
Document Center

BatchSendMessage

Last Updated: Jul 23, 2019

Description

This interface is used to send messages to the specified message queue in batches. A maximum of 16 messages can be sent in one BatchSendMessage operation.

A common message can be consumed by the consumer immediately after being sent to a message queue. The producer can set the DelaySeconds parameter when sending the message to consume later(the typical scenario is a scheduled task). The initial status of a message with the DelaySeconds value(>0) is Delayed. The message cannot be consumed till its status turns to Active after its DelaySeconds time expires In this status.

Tip:

The priority of the DelaySeconds parameter specified upon message sending is higher than the DelaySeconds attribute of the delayed message queue. That means, when the values of the two DelaySeconds attributes are different, the value of the DelaySeconds parameter specified upon message sending takes precedence.

Request

A request mainly includes the following parts:

  • Request line

    POST /queues/$queueName/messages HTTP/1.1

  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    Request Body is in XML format. XML contains the attributes for creating messages.

Parameter Name Description Parameter Value
MessageBody Required. Message body UTF-8 character set
DelaySeconds Optional. A delay time after which a message can be consumed, measured in seconds An integer between 0 and 604800 (7 days). The default value is 0
Priority Optional. Priority of a specified message. A message with a higher priority is more likely to be consumed earlier The value ranges from 1 to 16 (the value 1 indicates the highest priority). The default value is 8

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 201 Created

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    The return result is in XML format. The MessageId and MessageBodyMD5 sub-elements of multiple messages are returned.

Parameter Name Description
MessageId Message ID, which is unique in one queue.
MessageBodyMD5 MD5 value of the message body

Special Error:

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
MalformedXML The XML you provided was not well-formed. 400
InvalidArgument The value of Element should between Low and High seconds/bytes. 400

Request example:

  1. POST /queues/$queueName/messages HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 18 Mar 2012 12:00:00 GMT
  4. Content-Length:500
  5. Content-Type:text/xml;charset=utf-8
  6. x-mns-version: 2015-06-06
  7. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE
  8. <?xml version="1.0” encoding=”UTF-8” ?>
  9. <Messages xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  10. <Message>
  11. <MessageBody>Message1 Base64 Encoded Result</MessageBody>
  12. <DelaySeconds>60</DelaySeconds>
  13. <Priority>1</Priority>
  14. </Message>
  15. <Message>
  16. <MessageBody>Message2 Base64 Encoded Result</MessageBody>
  17. <DelaySeconds>60</DelaySeconds>
  18. <Priority>1</Priority>
  19. </Message>
  20. </Messages>

Response example:

  1. HTTP/1.1 201Created
  2. Connnection:close
  3. Content-Length:120
  4. Content-Type:text/xml;charset=utf-8
  5. x-mns-request-id:512B2A634403E52B1956133E
  6. x-mns-version: 2015-06-06
  7. <?xml version="1.0” encoding=”UTF-8” ?>
  8. <Messages xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  9. <Message>
  10. <MessageId>5F290C926D472878-2-14D9529A8FA-200000001</MessageId>
  11. <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
  12. </Message>
  13. <Message>
  14. <MessageId>5F290C926D472878-2-14D9529A8FA-200000002</MessageId>
  15. <MessageBodyMD5>377AC5283D8765C9CEE4E0EA353DFC17</MessageBodyMD5>
  16. </Message>
  17. </Messages>