Help Center > > Getting Started> Publishing a Message

Publishing a Message

Updated at: May 08, 2019 15:56

After you learn the basic concepts in SMN, you can start to create a topic, add subscriptions to the topic, and publish messages on the SMN console or by calling RESTful APIs provided by SMN. For details about SMN APIs, see the Simple Message Notification API Reference.

Figure 1 shows the process to publish a message to a topic.

Figure 1 Process to publish a message

Scenario

If you need to send similar messages repeatedly, you can create a message template which contains fixed and changeable content. Every time you send messages using the template, you only have to replace changeable content. For example, your organization holds expositions regularly and needs to notify relevant people of the dates, you can create a message template containing date variables and other fixed content.

Step 1. Create a Topic

  1. Log in to the management console.
  2. Click on the upper left to select the desired region and project.
  3. In the Application category, click Simple Message Notification.

    The SMN console is displayed.

  4. In the navigation pane, choose Topic Management > Topics.

    The Topics page is displayed.

  5. Click Create Topic.

    The Create Topic box is displayed.

  6. Enter a topic name and display name.
    Table 1 Information required for creating a topic

    Parameter

    Description

    Topic Name

    Topic name, which:

    • Contains only letters, numerals, hyphens (-), and underscores (_) and starts with a letter or numeral.
    • Is a string of 1 to 255 characters.
    • Must be unique and cannot be modified once the topic is created.

    Display Name

    Message sender name, which must be less than 192 bytes.

    NOTE:

    After you specify a display name, the sender in email messages will be presented as Display name<username@example.com>. Otherwise, the sender will be username@example.com.

  7. Click OK.

    The topic you created is displayed in the topic list. The system generates a topic URN, which is the unique resource identifier of the topic and cannot be changed.

  8. Click the name of the topic to view its details, including the subscriptions, URN, and display name.

Step 2. Add a Subscription

  1. Log in to the management console.
  2. Click on the upper left to select the desired region and project.
  3. In the Application category, click Simple Message Notification.

    The SMN console is displayed.

  4. In the navigation pane, choose Topic Management > Subscriptions.
  5. Click Add Subscription.

    The Add Subscription box is displayed.

  6. Specify the required subscription information.

    Click beside the Topic Name box to select a topic.

    Specify the subscription protocol and endpoints.
    Table 2 Required subscription information

    Parameter

    Description

    Topic Name

    Name of the topic to subscribe to

    Protocol

    Protocol the subscription endpoints support. The available options include SMS, Application, DMS, Email, HTTP, and HTTPS.

    Endpoint

    Subscription endpoint. You can enter up to 10 SMS, application, email, HTTP, or HTTPS endpoints, one in each line.

    • SMS: Enter one or more valid phone numbers. Only phone numbers in the Chinese mainland are supported,

      Example:

      18512345678

      +8618512345678

    • Email: Enter one or more valid email addresses.

      For example:

      username1@example.com

      username2@example.com

    • HTTP or HTTPS: Enter one or more public network URLs.

      For example:

      http://example1.com/notification/action

      http://example2.com/notification/action

    • DMS: Click to select a message queue. Ensure that the queue policy grants the DMS:ProduceMessages permission to SMN. For details, see section "Managing Queue Policies" in the Distributed Message Service User Guide.
    • Application: Obtain endpoint URNs on the Application Details page and enter them in the text box.
  7. Click OK.

    The subscription you added is displayed in the subscription list.

    NOTE:
    • To prevent a malicious user from attacking subscription endpoints, SMN controls the number of confirmation messages sent to an endpoint within a specified period of time. For details, see section "Traffic Control on Subscription Confirmation" in the Simple Message Notification User Guide.
    • SMN does not check whether subscription endpoints exist when you add subscriptions. However, subscribers will not receive notification messages until they confirm their subscriptions.
    • The token is valid only for 48 hours. Therefore, subscribers must confirm subscriptions within that time.

Step 3. Create a Message Template

  1. Log in to the management console.
  2. Click on the upper left to select the desired region and project.
  3. In the Application category, click Simple Message Notification.

    The SMN console is displayed.

  4. In the navigation pane, choose Topic Management > Message Templates.
  5. Click Create Message Template.

    The Create Message Template box is displayed.

  6. Specify the template name, protocol, and content.
    Table 3 Parameters required for creating a message template

    Parameter

    Description

    Template Name

    Template name, which:

    • Contains letters, numerals, underscores (_), and hyphens (-) and starts with a letter or numeral.
    • Is a character string 1 to 64 bytes long.
    • Cannot be modified once the template is created.

    Protocol

    Endpoint protocol of the template, which cannot be changed once the template is created

    The value can be Default, SMS, HTTP, HTTPS, Email, or DMS.

    If you do not specify a protocol, the Default protocol is used.

    Content

    Template content

    You can use variables as placeholders. Before you send messages using the template, SMN replaces the variables with the message content you specify. A variable is a string of up to 21 characters. It may contain upper- or lower-case letters, numerals, hyphens (-), underscores (_), and periods (.) and must start with a letter or numeral.

    The message template must meet the following requirements:

    • The template supports plain text only.
    • The template content cannot be left blank and cannot exceed 256 KB.
    • A template can contain up to 90 non-repeating variables or 256 variables counting the repeated ones.
    • When you send messages using a template, the message content you specify for each variable cannot exceed 1 KB.
    For example, the template information is as follows:
    • Template Name: tem_001
    • Protocol: Default
    • Content: The Arts and Crafts Exposition will be held from {startdate} through {enddate}. We sincerely invite you to join us.
  7. Click OK.

    The template you created is displayed in the template list.

Step 4. Publish a Template Message

  1. Log in to the management console.
  2. Click on the upper left to select the desired region and project.
  3. In the Application category, click Simple Message Notification.

    The SMN console is displayed.

  4. In the navigation pane, choose Topic Management > Topics.

    The Topics page is displayed.

  5. In the topic list, locate the topic to which you need to publish a message and click Publish Message under Operation.
  6. Configure the required parameters. The topic name is provided by default and cannot be changed.

    Select Template for Message Format. Then, manually type the template content in the Message box or click Generate Template Message to generate it automatically. The template message content cannot exceed 256 KB.

    • If you choose to manually type the template message, see "Template Message Format" in the Simple Message Notification User Guide for detailed requirements.
    • If you choose to automatically generate the template message, proceed with steps 7 through 10.
  7. Click Generate Template Message.
  8. Select a template name, for example, tem_001, and enter values for the variables.

    The system replaces the variables with the message content you specified. The protocols configured in the template are displayed after each variable. In the example shown in the following figure, only the default protocol is specified in tem_001. Therefore, all confirmed subscribers in the topic will receive the message content in the default template.

  9. Click the Preview tab to preview the message.

    In this example, the message generated is "The Arts and Crafts Exposition will be held from February 10 through February 21. We sincerely invite you to join us."

  10. Click OK.

    The message that is generated contains the template name and variables.

  11. Click OK.

    SMN delivers your message to all subscription endpoints. For details about messages for different protocols, see "Messages of Different Protocols" in the Simple Message Notification User Guide.

Step 5. Receive the Message

Subscription endpoints using different protocols receive different messages.
  • Email protocol

    Subscription endpoints are email addresses.

    Email messages contain the message subject, content, and a link to unsubscribe.

  • HTTP/HTTPS protocol

    Subscription endpoints are public network URLs. For details, see section "HTTP/HTTPS Messages" in the Simple Message Notification User Guide.

  • SMS protocol

    Subscription endpoints are phone numbers.

    SMS messages contain only the message content.

  • DMS protocol

    Subscription endpoints are message queues.

    Message content is not displayed in message queues. You can access the DMS console and check the number of messages in a queue. After you publish a message to a message queue, the number in that queue will increase.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel