Help Center/ Simple Message Notification/ Getting Started/ Publishing a JSON Message Using SMN
Updated on 2024-09-30 GMT+08:00

Publishing a JSON Message Using SMN

Scenarios

You can publish a JSON message to an SMN topic to broadcast the message to different types of subscription endpoints in the topic.

To start your experience with SMN, this topic describes how to create a topic and publish a JSON message.

Operation Process

Procedure

Description

Making Preparations

Sign up for a HUAWEI ID, complete real-name authentication, enable Huawei Cloud services, and top up your account.

Step 1: Create a Topic

Create a topic Mytopic.

Step 2: Add a Subscription

Add SMS and email subscriptions to the topic.

Step 3: Publish a Message

  • Publish a message "Dear Sir or Madam, this is an SMS message." to the SMS subscriber.
  • Publish a message "Dear Sir or Madam, this is an Email message." to the email subscriber.

Step 4: Receive the Message

The subscription endpoints receive the messages.

Making Preparations

  1. Sign up for Huawei Cloud and complete real-name authentication.

    Before using SMN, sign up for a HUAWEI ID, enable Huawei Cloud services, and complete real-name authentication.

    If you have enabled Huawei Cloud services and completed real-name authentication, skip this step.

  2. Top up your account.

    Ensure that the account balance is sufficient. If not, top up your account.

Step 1: Create a Topic

  1. Log in to the SMN console and go to the Create Topic page.
  2. Configure topic parameters.
    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Creating a Topic.
    Figure 1 Create Topic
    Table 1 Parameters for creating a topic

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic to be created.

    Enterprise Project

    default

    This parameter is displayed only for enterprise users who have enabled enterprise project management.

  3. Click OK.

    After a topic is created, the system generates a topic URN, which uniquely identifies the topic and cannot be changed. The topic you created is displayed in the topic list.

Step 2: Add a Subscription

Add SMS and email subscriptions to the topic.

  1. In the topic list, locate Mytopic and click Add Subscription in the Operation column.
  2. Configure subscription parameters.

    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Creating a Topic.

    Figure 2 Add Subscription
    Table 2 Parameters for adding an SMS subscription

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic you select to add subscriptions.

    Protocol

    SMS

    Select SMS from the Protocol drop-down list.

    For more supported protocols, see What Protocols Does SMN Support?

    Endpoint

    +8618612345678

    Enter a valid mobile number in the text box.

    • You can enter up to 10 endpoints, each on a separate line.
    • SMN does not check whether subscription endpoints exist when you add subscriptions.
  3. Click OK.

    After a subscription is added, the subscription endpoint receives a confirmation message. The recipient needs to click the subscription confirmation link on the subscription endpoint to confirm that they agree to receive messages published to the topic. On the SMN console, you can see that the subscription status is Confirmed.

  1. In the topic list, locate Mytopic and click Add Subscription in the Operation column.
  2. Configure subscription parameters.

    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Creating a Topic.

    Figure 3 Add Subscription
    Table 3 Parameters for adding an email subscription

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic you select to add subscriptions.

    Protocol

    Email

    Select Email from the Protocol drop-down list.

    For more supported protocols, see What Protocols Does SMN Support?

    Endpoint

    username@example.com

    Enter a valid email address in the text box.

    • You can enter up to 10 endpoints, each on a separate line.
    • SMN does not check whether subscription endpoints exist when you add subscriptions.
  3. Click OK.

    After a subscription is added, the subscription endpoint receives a confirmation message. The recipient needs to click the subscription confirmation link on the subscription endpoint to confirm that they agree to receive messages published to the topic. On the SMN console, you can see that the subscription status is Confirmed.

Step 3: Publish a Message

  1. In the topic list, locate Mytopic and click Publish Message in the Operation column.
  2. Configure parameters for publishing a message.
    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Publishing a JSON Message.
    Figure 4 Publish Message
    Table 4 Parameters for publishing a message

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic you select to publish a message.

    Message Format

    JSON

    Specifies in which format messages will be sent.

    Message

    {
        "default": "Dear Sir or Madam, this is a default message.",
        "sms": "Dear Sir or Madam, this is an SMS message.",
        "email": "Dear Sir or Madam, this is an Email message."
    }

    You can manually enter a message in JSON format or click Generate JSON Message to automatically generate a message.

    For details, see JSON Message Format.

  3. Click OK.

    For details about messages, see Messages Using Different Protocols.

Step 4: Receive the Message

Subscription endpoints of different protocols receive different messages.

  • SMS

    SMS messages only contain the message content.

  • Email

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