Publishes a message to a topic. After the message is published, Simple Message Queue (formerly MNS) pushes it to the specified endpoints.
Request syntax
POST /topics/$TopicName/messages HTTP/1.1Replace $TopicName with the name of the target topic.
Request headers
This operation uses common request headers only. For more information, see Common parameters.
Request body
The request body is an XML message with the following elements.
| Parameter | Type | Required | Description |
|---|---|---|---|
| MessageBody | String | Yes | The message content. |
| MessageTag | String | No | The message tag. |
| MessageAttributes | Object | Yes | The push endpoint type. Valid values: HTTP (HTTP gateway) and Queue (push to an SMQ queue). |
Note
The XML namespace must be http://mns.aliyuncs.com/doc/v1/. Requests that omit or use an incorrect namespace return an error.
Response parameters
| Parameter | Type | Example | Description |
|---|---|---|---|
| MessageId | String | D273CD6A89564E54-1-15180395A19-20000\*\*\*\* | A unique identifier for the message within the topic. |
| MessageBodyMD5 | String | 3AC6DD36D2D6B7283F2F490A0975\*\*\*\* | The MD5 hash of the message body. Compare this value against a locally computed hash to verify message integrity. |
Sample success response
Sample success response
HTTP/1.1 201 Created
Content-Length:120
Content-Type:text/xml;charset=utf-8
x-mns-request-id:56667514B2B71C9C1600****
x-mns-version:2015-06-06
<?xml version="1.0" encoding="utf-8"?>
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
<MessageId>D273CD6A89564E54-1-15180395A19-20000****</MessageId>
<MessageBodyMD5>3AC6DD36D2D6B7283F2F490A0975****</MessageBodyMD5>
</Message>Error codes
For errors common to all operations, see Common parameters.
The following table lists the error codes specific to the PublishMessage operation.
| HTTP status code | Error code | Error message | Description |
|---|---|---|---|
| 404 | TopicNotExist | The topic you provided does not exist. | The topic name in the request URI does not match any existing topic. Verify the topic name. |