Sends a message to a specified message queue. A message can be consumed after it is sent to message queue. However, if you need to delay the consumption of a message in specific scenarios, for example, scheduled tasks, you can set the DelaySeconds parameter to an integer greater than 0. In this case, after a message is sent to a queue, the status of the message is Delayed and the message cannot be consumed. After the delay period expires, the status changes to Active and the message can be consumed.

Request

A request consists of the following parts:

  • Request line

    POST /$queueName/messages HTTP/1.1

  • Operation-specific request headers

    None. For information about common request parameters, see Common parameters.

  • Request Body
    The request body is in the XML format. It contains the parameters of the message.
    Parameter Description Value
    MessageBody Required. The body of the message. UTF-8 characters.
    DelaySeconds Optional. The interval between the time when a message arrives at the queue and the time when the message becomes consumable. Unit: seconds. Valid values: 0 to 604800 (7 days). Data type: integer. Default value: 0.
    Priority Optional. The priority of the message. A message with a higher priority is consumed earlier. Valid values: 1 to 16. The value 1 indicates the highest priority. Default value: 8.
    Note If the value of the DelaySeconds parameter in the SendMessage request is different from that of the message queue, the value in the SendMessage request is used.

Response

A response consists of a status line, HTTP headers, and a response body.

  • HTTP Status Code

    HTTP/1.1 201 Created

  • Operation-specific response headers

    None. For information about common response parameters, see Common parameters.

  • Response Body

    The response is in the XML format. The MessageId and MessageBodyMD5 parameters are returned.

    Parameter Description
    MessageId The ID of the message. Each message ID is unique in the queue.
    MessageBodyMD5 The MD5 hash of the message body.

Special Error

Error code Error message HTTP 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
  • Sample requests
        POST /$queueName/messages HTTP/1.1
        Host: $AccountId.mqs-cn-hangzhou.aliyuncs.com
        Date: Wed, 18 Mar 2012 12:00:00 GMT
        Content-Length:500
        Content-Type:text/xml;charset=utf-8
        x-mqs-version: 2014-07-08
        Authorization: MQS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE
    
        <? xml version="1.0" encoding="UTF-8" ? >
        <Message xmlns="http://mqs.aliyuncs.com/doc/v1/">
            <MessageBody>Base64 Encoded Result</MessageBody>
            <DelaySeconds>60</DelaySeconds>
            <Priority>1</Priority>
        </Message>            
  • Sample success responses
        HTTP/1.1 201Created
        Connection:close
        Content-Length:120
        Content-Type:text/xml;charset=utf-8
        x-mqs-request-id:512B2A634403E52B1956133E 
        x-mqs-version:2015-06-06
    
        <? xml version="1.0" encoding="UTF-8" ? >
        <Message xmlns="http://mqs.aliyuncs.com/doc/v1/">
            <MessageId>5F290C926D472878-2-14D9529A8FA-200000001</MessageId>
            <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
        </Message>