Call PublishMessage to publish a message to a specific topic. The message is then pushed to an endpoint for consumption.
Request headers
This operation uses common request headers. No special request headers are required. For more information, see Common parameters.
Request syntax
POST /topics/$TopicName/messages HTTP/1.1
Base64-encode the message body before you send the message to prevent errors caused by special characters.
Request parameters
Parameter | Type | Required | Description |
MessageBody | String | Yes | The message content. |
MessageTag | String | No | The message tag. |
MessageAttributes | Object | No | The message attributes. This parameter is not required when messages are pushed to a queue or over HTTP. |
Response data
Parameter | Type | Example | Description |
MessageId | String | D273CD6A89564E54-1-15180395A19-20000**** | The ID of the message. The ID is unique within the topic. |
MessageBodyMD5 | String | 3AC6DD36D2D6B7283F2F490A0975**** | The MD5 hash of the message body. |
Examples
Request example
POST /topics/MyTopic/messages HTTP/1.1
Host: 123456789098****.mns.cn-hangzhou.aliyuncs.com
Date: Tue, 08 Dec 2015 06:13:40 GMT
Content-Length:500
Content-Type:text/xml;charset=utf-8
Authorization: MNS 15B4D3461F177624****:aibzWu1iDEx9LwO56+kHgA3e****
x-mns-version: 2015-06-06
<?xml version="1.0" encoding="UTF-8"?>
<Message xmlns="http://mns.aliyuncs.com/doc/v1">
<MessageBody>hello topic</MessageBody>
</Message>Response example
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
Error code | Error message | Status code |
TopicNotExist | The topic you provided does not exist. | 404 |