nav-img
Advanced

Publishing a JSON Message

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.

We will walk you through the following operations in the example:

  • Create a topic Mytopic.
  • Add email subscriptions to the topic.
  • Publish a message "Dear Sir or Madam, this is an email message." to the email subscriber.

Operation Process

Figure 1 shows the process to publish a JSON message.

Figure 1 Process of publishing a JSON message


Step 1. Create a Topic

  1. Log in to the management console.
  2. Under Application, select Simple Message Notification.

    The SMN console is displayed.

  3. In the navigation pane on the left, choose Topic Management > Topics.
  4. In the upper right corner, click Create Topic.

    Figure 2 Create Topic


  5. Set Topic Name to Mytopic.
  6. 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.

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

Step 2. Add a Subscription

  1. In the navigation pane on the left, choose Topic Management > Subscriptions.
  2. On the Subscriptions page, click Add Subscription.

    The Add Subscription dialog box is displayed.

  3. Add an email subscription to a topic.
    1. Click beside the Topic Name box to select Mytopic.
    2. Select Email from the Protocol drop-down list.
    3. In the Endpoint box, enter the subscription endpoint, for example, username@example.com.

      Enter one endpoint on a separate line.

    4. 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 navigation pane on the left, choose Topic Management > Topics.

    The Topics page is displayed.

  2. Locate Mytopic and click Publish Message in the Operation column.
  3. On the Publish Message page, configure the following parameters:
    • Topic Name: The topic name is displayed by default.
    • Message Format: JSON
    • 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."
      }

  4. Click OK to deliver your message to all subscription endpoints.

Step 4. Receive the Message

Subscription endpoints of different protocols receive different messages.

  • Email Message

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