Using Streams and Subscriptions for Alerting

Chait Diwadkar
Chait Diwadkar
/
Share on LinkedIn

One of the many ways in which TDengine simplifies application development is by offering stream processing and publish/subscribe features that are built into TDengine. This also reduces the complexity of deploying a time-series application which would usually involve setting up a stream processing platform like Kafka or using Kafka or a message broker as a pub/sub platform.

TDengine offers this functionality in the platform itself and setting up streams and topics is as simple as writing SQL or using the UI in TDengine Cloud or TDengine Enterprise to write the SQL for you.

Table of Contents

Video Tutorial

Steps

In the video, we demonstrate how to setup an alerting system for a solar farm, which sends an SMS when the power output of a solar panel falls below a certain threshold.

In order for you to go through this video, you will have watch and follow the steps in the previous blog in which we set up an OPC connector to read data from a solar farm.

At a high level in this video we do the following:

  1. Set up a stream which aggregates the power output from each panel for the prior 5 minutes.
  2. Streams always write the aggregated results to a different supertable and, in our case, we write the aggregated data to a supertable called “p5”
  3. We then set up a topic which looks at the “p5” supertable and writes data to a topic when the output power falls below a threshold that we have set to be 10.
  4. We then use the sample code provided by TDengine to create a Python application to subscribe to the topic.
  5. We use the Twilio API to send an SMS to a number when data is published on this topic.

Note that, you can design any kind of alerting system you want and are not limited to using Twilio APIs.

Also note that in a real production system for a solar farm, your application would need to be more robust and, for example, lookup the sunset and sunrise times to ensure you don’t send alerts between those hours.

Data Sharing

While we have not shown this in the video, data subscriptions can also be used to share data with 3rd party stakeholders. TDengine Cloud does not have a limit on the number of users for your organization. Since data subscriptions are created using SQL, you can get very granular in terms of the data you share. Of course, with data subscriptions, 3rd parties would have to consume the data in the subscription using TDengine APIs and then do something with the data in their application. But sharing the data is very simple as illustrated below.

In Fig 1 below, you can see the topic that was created in the video.

This takes you to the next screen. Make sure the right topic is showing in the drop down and then click on the “Add user to consume this topic” button.

This user also needs to be given “read” permission on the “p5” supertable on which this topic is created.

Then, when this user logs into their account, they will see the following in the “Topics” screen.

Conclusion

To conclude, using the Stream Processing and Subscriptions functionality in TDengine allows you to create fairly powerful applications and allows you to share data at a very granular level with many stakeholders with just an email address and role-based access control.

  • Chait Diwadkar
    Chait Diwadkar

    Chait Diwadkar is Director of Solution Engineering at TDengine. Prior to joining TDengine he was in the biotechnology industry in technical marketing, professional services, and product management roles and supported customers in pharma, medical devices and diagnostics on analytical chemistry, and genetic platforms.