Updated on 2022-02-24 GMT+08:00

Data Subscription

Overview

An NA calls the Subscribing to Service Data of the IoT Platform API to notify the IoT platform of message push addresses and notification types, such as device service data and device alarms. For details about the subscription API, see the API reference document.

In the subscription scenario, the IoT platform is the client, and the NA is the server. The IoT platform calls the API of the NA and pushes messages to the NA. If the subscription callback URL is an HTTPS address, a CA certificate must be uploaded to the IoT platform. The CA certificate is provided by the NA. (For details on how to obtain the certificate, see Exporting a CA Certificate.) To load a CA certificate, choose Applications > Interconnection, and click Certificate Management and Add in the Push Certificate area. For details, see Uploading a CA Certificate.

This topic describes how to call the subscription API based on the Java code sample of the API.

Procedure

  1. In the Eclipse, choose src > com.huawei.utils > Constant.java, modify CALLBACK_BASE_URL, and enter the callback URL and port number.

    In the same application, the callback URL and port number of all subscription types must be the same. Subscription Test of the Developer Center checks the validity and connectivity of callback URLs.

  2. In the Eclipse, choose src > com.huawei.service.subscribtionManagement, right-click SubscribeServiceNotification.java, and choose Run As > Java Application.

  3. View the response log on the console. If all types of subscriptions receive "201 Created" response, the subscription is successful.

    NOTE:
    • To modify the callback URL, change the value of CALLBACK_BASE_URL in the Constants.java file and run

      SubscribeServiceNotification.java. The new callback URL replaces the original one.

    • After the subscription is complete, you can choose src > com.huawei.testMessagePush > SimpleHttpServer.java to set up an NA to receive messages (for example, POST messages) pushed by the IoT platform. If you need to perform a local test on the callback function and view the callback content, use the class src > com.huawei.testMessagePush > TestSubscribeAllServiceNotification.java provided in the Northbound JAVA API Demo and refer to the operations in Data Reporting.