Getting Started: Subscribing to Basic Alert Data¶
This guide shows how to configure an alert data subscription job on the EnOS Management Console and use the SDK provided by EnOS to consume the alert data.
The function list of EnOS Cloud and EnOS Edge is as follows:
Feature |
EnOS Cloud |
EnOS Edge |
---|---|---|
OUs |
Multiple OUs |
Single OU |
Message channel |
Basic, advanced alert service |
Basic alert service |
Subscribed content |
Device model, device tag, asset tree tag |
Device model, device tag, asset tree tag |
Prerequisites¶
You are able to access the Data Subscription module.
The device is connected and is uploading data to EnOS.
The service account (SA) for subscribing data has been authorized to access asset data. For authorizing the service account, see Managing Service Accounts
You have a workstation with IDE (for Java or Python) installed.
Goal and Data Preparation¶
Goal
The goal of this guide is to subscribe to the alert data of the test_raw measurement point.
Data Preparation
Model configuration: The model used in this guide (testModel) is configured as follows.
Feature Type |
Name |
Identifier |
Point Type |
Data Type |
---|---|---|---|---|
Measurement Point |
test_raw |
test_raw |
AI |
double |
Data ingestion: Alert settings are configured for monitoring the data of the test_raw measurement point. For information about data ingestion, see Device Connection.
Alert Configuration: For information about alert configuration for devices, see Alert Engine.
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 the subscribed data with Java SDK.
Check the data consumption results.
Step 1. Create and Configure a Data Subscription Job¶
EnOS Cloud: Log in to the EnOS Management Console and select the Subscription Service module.
EnOS Edge: Log in to the EnOS Management Console and select the Edge Management module. Then go to Edge Details > Data Subscription.
All the subscription jobs created for the current organization are listed in the table. Follow the steps below to create and configure an alert data subscription job.
Click the New Subscription button and complete the configuration for the job. For this guide, select Alert Data Subscription as the type.
ID: Enter or generate an ID for the subscription job.
SA: Select an SA account. Each consumer instance must have an associated SA account, which can be generated by registering an application on EnOS. Here SA is the account of the registered application on EnOS Edge.
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.
Description: Enter a short description for the data subscription job.
Clients (EnOS Cloud only): Each SA can access the data of multiple clients (through purchasing applications). Select the clients whose data you want to subscribe to.
Model Filter: Select the model to subscribe to. For this guide, select testModel. The subscription system will filter the alert data to meet the specified conditions.
Device Tags / Asset Tree Tags (Optional): You can choose to set device tags or asset tree tags to filter the subscribed data to subscribe only to the alert data of the specified devices or asset trees.
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, and click the Enable icon to run the subscription job.
Step 3. Get Subscribed Data with Java or Python SDK¶
EnOS provides SDKs to help you with offline application development and data consumption. The following example is for consuming subscribed data with Java SDK:
EnOS Cloud Code Sample¶
Add Maven dependency for the SDK. See the following example:
<dependency> <groupId>com.envisioniot</groupId> <artifactId>subscription-client</artifactId> <version>5.0.2</version> </dependency> <dependency> <groupId>com.envisioniot</groupId> <artifactId>enos-subscribe-impl</artifactId> <version>5.0.2</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.0</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</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);
EnOS Edge Code Sample¶
Add Maven dependency for the SDK. See the following example:
<dependency> <groupId>com.envisioniot</groupId> <artifactId>subscription-client</artifactId> <version>5.0.2</version> </dependency> <dependency> <groupId>com.envisioniot</groupId> <artifactId>edge-subscribe-impl</artifactId> <version>1.0.5</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.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, ture); 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 will 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 the 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.