HTTP or HTTPS Message Format

Scenarios

Caution

When receiving HTTP or HTTPS messages sent by SMN, refer to the industry standards for the common name (CN) of the terminal certificate. Some special characters may cause HTTPS message sending failures.

This section describes the format of messages sent to HTTP or HTTPS endpoints. You can identify messages based on message types in the headers. HTTP/HTTPS message types include: subscription confirmation messages, notification messages, and subscription cancellation messages. POST is used for HTTP/HTTPS messages.

The header of an SMN HTTP/HTTPS message contains the following parameters: X-SMN-MESSAGE-TYPE, X-SMN-MESSAGE-ID, X-SMN-TOPIC-URN, and X-SMN-SUBSCRIPTION-URN.

Table 1 HTTP header fields

Parameter

Description

X-SMN-MESSAGE-TYPE

Indicates the message type, which can be:

  • SubscriptionConfirmation

  • Notification

  • UnsubscribeConfirmation

X-SMN-MESSAGE-ID

Indicates the unique message ID.

X-SMN-TOPIC-URN

Indicates the URN of the topic the message belongs to.

X-SMN-SUBSCRIPTION-URN

Identifies the subscription endpoint.

This parameter is required only when messages are pushed over HTTP/HTTPS and when you cancel your HTTP/HTTPS subscriptions.

Note

The requirements for HTTP header fields are described as follows:

  • According to section 3.2 in RFC 7230, header fields should be case insensitive.

  • According to section 8.1.2 in RFC 7540, header fields in HTTP/2 should be lowercase.

  • Custom HTTP header fields must comply with the above two requirements for SMN.

  • You are advised to use case-insensitive letters to obtain HTTP header fields.

HTTP/HTTPS Subscription Confirmation Message Format

After you add an HTTP/HTTPS endpoint, SMN sends a subscription confirmation message to the subscriber. The message body is composed of JSON character strings. The subscriber must obtain the subscription URL (subscribe_url) to confirm the subscription. Table 2 describes the JSON field in detail.

Table 2 HTTP/HTTPS subscription confirmation message body

Parameter

Description

type

Indicates the message type. Its value is SubscriptionConfirmation.

signature

Indicates the signature information.

The signature includes the message, message_id, subscribe_url, timestamp, topic_urn, and type fields. For details about signature verification, see Message Signature Verification.

topic_urn

Indicates the URN of the topic the message belongs to.

message_id

Indicates the unique message ID.

signature_version

Indicates the signature version, which is V1.

message

Indicates the message content.

subscribe_url

Indicates the URL to be accessed for subscription confirmation.

signing_cert_url

Indicates the certificate URL for a message signature. It can be directly accessed without authentication.

timestamp

Indicates the time stamp when the message was initially sent.

The following is an example HTTP/HTTPS subscription confirmation message:

{
    "signature": "ViE96uGbBkl+S8eWqgebi5KdmRht2U8+Rs88yuyMHq1k4h3jUkcDZ6HCqTqdpJ8nrLcdqETyyEiOQyTszJdU05z+LhfE8jerCCdSbL4zeInVkydHh0kcCRWmORye0/EuQ/gLC1UIXwvUsqbUCPnBRhNFXOeXMOPPCzK+d04xjy4QHd1H/bHxgsY3AlTe0gCFT068Zru7OK6w9aQaY44mXnN3OWGmBmoHyFab5TRXLSQNz/9u/Vj646cQMMaI0PPQ30QzGYD0MtzgDZi12m8jMTHAnMkTEcbLaEgaqmaoEnATSpEcspFKNXv2skwk7rsVakMOISpMH3+qC6RzhETA2A==",
    "topic_urn": "urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic",
    "message_id": "d86c201092574e71a3ca85826652c58b",
    "signature_version": "v1",
    "type": "SubscriptionConfirmation",
    "message": "You are invited to subscribe to topic: urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic. To confirm this subscription, please visit the subscribe_url included in this message. The subscribe_url is valid only within 48 hours.",
    "subscribe_url": "https://console.xxx.com/smn/subscription/unsubscribe?subscription_urn=urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic:653e212a43884f7188ca656c537e31ce",
    "signing_cert_url": "https://console.xxx.com/smn/SMN_region01_b3974c411807498bb532b3cd6cd65d91.pem",
    "timestamp": "2019-08-12T22:40:56Z"
}

HTTP/HTTPS Notification Message Format

After an HTTP/HTTPS subscriber confirms the subscription, the subscriber can receive notification messages published to the topic. The notification message body is composed of JSON character strings, which are described in Table 3.

Table 3 HTTP/HTTPS notification message body

Parameter

Description

type

Indicates the message type. Its value is Notification.

signature

Indicates the signature information.

The signature includes the message, message_id, subject, timestamp, topic_urn, and type fields. If the subject field is empty, the signature is not verified. For details about signature verification, see Message Signature Verification.

subject

Indicates the message subject.

topic_urn

Indicates the URN of the topic the message belongs to.

message_id

Indicates the unique message ID.

signature_version

Indicates the signature version, which is V1.

message

Indicates the message content.

unsubscribe_url

Indicates the URL for canceling a subscription.

signing_cert_url

Indicates the certificate URL for generating the message signature.

timestamp

Indicates the time stamp when the message was initially sent.

The following is an example HTTP/HTTPS notification message:

{
    "signature": "ViE96uGbBkl+S8eWqgebi5KdmRht2U8+Rs88yuyMHq1k4h3jUkcDZ6HCqTqdpJ8nrLcdqETyyEiOQyTszJdU05z+LhfE8jerCCdSbL4zeInVkydHh0kcCRWmORye0/EuQ/gLC1UIXwvUsqbUCPnBRhNFXOeXMOPPCzK+d04xjy4QHd1H/bHxgsY3AlTe0gCFT068Zru7OK6w9aQaY44mXnN3OWGmBmoHyFab5TRXLSQNz/9u/Vj646cQMMaI0PPQ30QzGYD0MtzgDZi12m8jMTHAnMkTEcbLaEgaqmaoEnATSpEcspFKNXv2skwk7rsVakMOISpMH3+qC6RzhETA2A==",
    "topic_urn": "urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic",
    "message_id": "d86c201092574e71a3ca85826652c58b",
    "signature_version": "v1",
    "type": "Notification",
    "message": "{\"enterpriseProjectId\": \"0\", \"eventTime\": \"2019-08-12 22:40:55.040632\", \"chargingMode\": \"postPaid\", \"cloudserviceType\": \"xxx.service.type.bandwidth\", \"eventType\": 1, \"regionId\": \"region01\", \"tenantId\": \"057eefe55400d2742f8cc0017870ceef\", \"resourceType\": \"xxx.resource.type.bandwidth\", \"resourceSpecCode\": \"19_bgp\", \"resourceSize\": 10, \"resourceId\": \"e091f1b1-08ef-4e2b-a27e-f85e4c19026a\", \"resouceSizeMeasureId\": 15, \"resourceName\": \"elbauto_2019_08_13_06_40_46\"}",
    "unsubscribe_url": "https://console.xxx.com/smn/subscription/unsubscribe?subscription_urn=urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic:653e212a43884f7188ca656c537e31ce",
    "signing_cert_url": "https://console.xxx.com/smn/SMN_region01_b3974c411807498bb532b3cd6cd65d91.pem",
    "timestamp": "2019-08-12T22:40:56Z"
}

HTTP/HTTPS Subscription Cancellation Message Format

After an HTTP/HTTPS subscription is canceled, the subscriber receives a subscription cancellation message sent by SMN. The message body is composed of JSON character strings, which are described in Table 4.

Table 4 Parameters of HTTP/HTTPS subscription cancellation message format

Parameter

Description

type

Indicates the message type. Its value is UnsubscribeConfirmation.

signature

Indicates the signature information.

The signature includes the message, message_id, subscribe_url, timestamp, topic_urn, and type fields. For details about signature verification, see Message Signature Verification.

topic_urn

Indicates the URN of the topic the message belongs to.

message_id

Indicates the unique message ID.

signature_version

Indicates the signature version, which is V1.

message

Indicates the message content.

subscribe_url

Indicates the URL for a re-subscription.

signing_cert_url

Indicates the certificate URL for generating the message signature.

timestamp

Indicates the time stamp when the message was initially sent.

The following is an example HTTP/HTTPS message for canceling a subscription:

{
    "signature": "ViE96uGbBkl+S8eWqgebi5KdmRht2U8+Rs88yuyMHq1k4h3jUkcDZ6HCqTqdpJ8nrLcdqETyyEiOQyTszJdU05z+LhfE8jerCCdSbL4zeInVkydHh0kcCRWmORye0/EuQ/gLC1UIXwvUsqbUCPnBRhNFXOeXMOPPCzK+d04xjy4QHd1H/bHxgsY3AlTe0gCFT068Zru7OK6w9aQaY44mXnN3OWGmBmoHyFab5TRXLSQNz/9u/Vj646cQMMaI0PPQ30QzGYD0MtzgDZi12m8jMTHAnMkTEcbLaEgaqmaoEnATSpEcspFKNXv2skwk7rsVakMOISpMH3+qC6RzhETA2A==",
    "topic_urn": "urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic",
    "message_id": "d86c201092574e71a3ca85826652c58b",
    "signature_version": "v1",
    "type": "UnsubscribeConfirmation",
    "message": "You are unsubscribed from topic: urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic. To subscribe to this topic again, please visit the subscribe_url included in this message. The subscribe_url is valid only within 48 hours.",
    "subscribe_url": "https://console.xxx.com/smn/subscription/unsubscribe?subscription_urn=urn:smn:region01:0553db98c800d5192f9bc01232b89622:vpc_status_report_topic:653e212a43884f7188ca656c537e31ce",
    "signing_cert_url": "https://console.xxx.com/smn/SMN_region01_b3974c411807498bb532b3cd6cd65d91.pem",
    "timestamp": "2019-08-12T22:40:56Z"
}