HttpEndpoint
You can use the HttpEndpoint interface to push notifications to an endpoint by sending a POST request.
Description
Simple Message Queue (formerly MNS) pushes notifications to an endpoint by sending a POST request. Notifications support two formats:
- XML format
The request body includes the message content and metadata.
- SIMPLIFIED format
The request body is the unmodified message content. The MessageId is delivered in the request header.
Request
A request consists of the following parts:
- Request line
POST /notifications HTTP/1.1The default URI is
/notifications. If the endpoint specified during subscription creation contains a URI, that URI replaces/notifications. - Specific URI parameters
None.
- Specific request headers
Parameter Description Notes Authorization The signature of the push request. Included in both XML and SIMPLIFIED formats. x-mns-signing-cert-url The URL of the signing certificate (Base64-encoded). Included in both XML and SIMPLIFIED formats. x-mns-request-id The request ID of the pushed message. Included in both XML and SIMPLIFIED formats. x-mns-message-id The MessageId of the pushed message. Included in SIMPLIFIED format. x-mns-message-tag The message tag of the pushed message. Included in SIMPLIFIED format. - Request body
In XML format, the request body is an XML file that contains the message content and metadata.
Parameter Name Description TopicOwner The owner of the subscribed topic. TopicName The name of the subscribed topic. Subscriber The subscriber. SubscriptionName The subscription name. MessageId The message ID. Message The message content. MessageMD5 The MD5 hash of the message. MessageTag The message tag for message filtering. PublishTime The time when the message was published. This is the number of milliseconds from 00:00:00 on January 1, 1970 to the time of publication. In SIMPLIFIED format, the request body is the message content published by the publisher.
Response
The response consists of a status line, HTTP headers, and a message body:
- HTTP status code
HTTP/1.1 204 No Content- A 204 status code is returned if the notification message is processed correctly. If a 204 status code is not returned within 5 seconds, a timeout occurs. The service then retries pushing the message.
- A 403 status code is returned if the request signature validation fails.
- A 500 status code is returned for any other fault.
- Specific response headers
None.
- Response body
None.
Examples
Request examples:
- XML format
POST /notifications HTTP/1.1 Host: example.com Date: Tue, 08 Dec 2015 06:42:00 GMT Content-Length: 300 Content-Type: text/xml;charset=utf-8 Content-MD5: OGQzNjAwYjIwMWFiMTliZDlhNzc4YjAwZjc5MGQ4**** Authorization: QSNS+vn3IqJI4lOh4X/dxTv7Qebi/wrEaBJlzFFTc0hJVRUmrHLQo24ojBUETpz48+jrsjxMGPJTILDw752J**** User-Agent: Aliyun Notification Service Agent x-mns-request-id: 56667BB81FD0E7D12000**** x-mns-version: 2015-06-06 x-mns-signing-cert-url: aHR0cDovL21uc3Rlc3Qub3NzLWNuLWhhbmd6aG91LmFsaXl1bmNzLmNvbS94NTA5X3B1YmxpY19jZXJ0aWZpY2F0ZS5w**** <?xml version="1.0" encoding="utf-8"?> <Notification xlmns="http://mns.aliyuncs.com/doc/v1/"> <TopicOwner>$TopicOwner</TopicOwner> <TopicName>$TopicName</TopicName> <Subscriber>$Subscriber</Subscriber> <SubscriptionName>$SubscriptionName</SubscriptionName> <MessageId>6CC4D900CA59A2CD-1-15180534A8F-20000****</MessageId> <Message>{1:"a", 2:"b"}</Message> <MessageMD5>F1E92841751D795AB325861034B5****</MessageMD5> <MessageTag>important</MessageTag> <PublishTime>1449556920975</MessagePublishTime> </Notification> - SIMPLIFIED format
POST /notifications HTTP/1.1 Host: example.com Date: Tue, 15 Dec 2015 09:12:46 GMT Content-Length: 487 Content-Type: text/plain;charset=utf-8 Content-MD5: NmY4Njk0MzlmNzg3NTFkMTJiN2M5OWE4ZmYzNTU4**** Authorization: aXZIpRkRmIavmwceCyrPatB7SaEbOJdWpmFWYX3nFwtmaixK/M/3kl1njY0pgM7mrIB7NlBv5NfUZNkcIjlO**** User-Agent: Aliyun Notification Service Agent x-mns-message-id: 6CC4D900CA59A2CD-1-15180534A8F-20000**** x-mns-message-tag: important x-mns-request-id: 566FD963B2B71C44481F**** x-mns-signing-cert-url: aHR0cDovL21uc3Rlc3Qub3NzLWNuLWhhbmd6aG91LmFsaXl1bmNzLmNvbS94NTA5X3B1YmxpY19jZXJ0aWZpY2F0ZS5w**** x-mns-version: 2015-06-06 {1:"a", 2:"b"}
Response example:
HTTP/1.1 204 No Content