Getting Started: Subscribing to Alert Data

This guide introduces how to configure an alert data subscription job on EnOS Console and consume alert data with the Java SDK provided by EnOS.

Prerequisites

  • Access permission to the Data Subscription module.
  • Device connection is completed, and the devices are uploading data to EnOS.
  • The service account (SA) for subscribing data has been authorized to access asset data.
  • A workstation with IDE (IDEA or Eclipse) installed.

About This Task

Goal

The goal of this guide is to configure subscription to the alert data of measuring point test_raw.

Data Preparation

  • Model configuration: Detailed information about the (testModel) for this guide is as follows:
Feature Type Name Identifier Point Type Data Type
Measuring Point test_raw test_raw AI DOUBLE
  • Data ingestion: Alert settings are configured for monitoring the data of the test_raw measuring point. For information about data ingestion, see Device Connection.
  • Alert Configuration: For information about alert configuration for devices, see Alert Management.

Procedure

The steps for subscribing and consuming alert data are as follows:

  • Create and configure an alert data subscription job
  • Save and enable the subscription job
  • Get subscribed data with Java SDK
  • Check the data consumption results

Step 1. Create and Configure a Data Subscription Job

Log in EnOS Console and select the Subscription Service module. All the subscription jobs created for the current organization are listed in the table. Take the following steps to create and configure an alert data subscription job.

  1. Create Job: Click the New Subscription button and complete the configuration for the job. For this guide, select Alert Data Subscription as the type.

  2. Subscription ID: Choose to input or generate an ID for the subscription job.

  3. Select SA account: Each consumer instance must have an associated SA account, which can be generated by registering an application on EnOS. For instructions, see Managing Applications.

    Note

    The SA account associated with the data subscription job must be authorized to access the asset data. Otherwise, the data subscription job will fail because of authentication failure. For more information about authorizing the SA account, see Managing Service Accounts.

  4. Select data to be subscribed to: Each SA can access the data of multiple clients (through purchasing applications). Select the clients whose data are to be subscribed to.

  5. Set model filter: Select the model to be subscribed to. For this guide, select testModel. The subscription system will filter alert data to meet the specified condition.

  6. (Optional)You can choose to set device tags or asset tree tags to filter the subscribed data, subscribing to alert data of the specified devices or asset trees only.

Step 2. Save and Enable the Subscription Job

After the subscription job is configured, click Save to save the configuration. On the Data Subscription page, find the created job, click the Enable icon to start the subscription job.

Step 3. Get Subscribed Data with Java SDK

EnOS provides Java SDK to help you with offline application development and data consumption.

<dependency>
  <groupId>com.envisioniot</groupId>
  <artifactId>enos-subscribe</artifactId>
  <version>2.3.0</version>
</dependency>
  • Use IDE for offline application development. See the following code sample:
String sub_server_host ="sub_server_host";
int sub_server_port ="sub_server_port";
String accessKey ="access_Key";
String secretKey ="secret_Key";
String subId = "subscriptionId";
String consumerGroup = "consumerGroup";   /* Optional */

/* service */
EOSClient eosClient = new EOSClient(sub_server_host, sub_server_port, accessKey, secretKey);
IAlertService alertService = eosClient.getAlertService();

/* handler */
IAlertHandler alertHandler = new IAlertHandler(){
    @Override
    public void alertRead(Alert alert) {
        System.out.println(alert);
    }
};

/* subscribe */
alertService.subscribe(alertHandler, subId);

/* (Optional) subscribe with consumer group (optional) */
alertService.subscribe(alertHandler, subId, consumerGroup);

Note

In this sample, the sub_server_host and sub_server_port are the host and port of the subscription server, which vary with the cloud region and instance. For private cloud instances, contact your Envision project manager or support representative to get the host and port information.

For more information about the SDK, see Data Subscription SDK Reference.

Step 4. Check the Data Consumption Results

Run the application for data consumption and check the data consumption results in the logs of the application.