Thingsboard Detailed rules engine, rules engine how to use TB

First, what rule engines?

The official explanation: "rule by the inference engine developed from the engine, is a component embedded in an application to achieve the separation of business decisions from the application code out and use predefined business decision to accept the semantic modules written data. input, explain the business rules, and make business decisions based on business rules. "
Thingsboard explained: Thingsboard platform core processing engine, like a car engine, it is to build event-based workflow is a highly customizable framework, with complex event processing.
image.png

Second, what Thingsboard rules engine capabilities are?

1, stored in the device data (real time data / attribute data) before database support for telemetry data or attribute data received intercept verification and modification;
2, the device telemetry data (real time data) device attribute copy or from the device to the associated assets, so that can be aggregated telemetry;
3, a custom alert rules / function, for device alarm is triggered, update, clear;
4, triggering device operating according to life cycle events. ; Device such as a line, the device offline, alarm event create
additional data required to process 5, loading. Temperature of the load device in a defined threshold or the client device tenant properties;
7, when transmitting e-mail complex event occurs, and using the "e-mail template" attribute other entities;
8, the remote control apparatus according to the conditions defined RPC transfer.
9, the real-time data device, the remote control RPC command or an alarm or an event triggered by a rule engine, to push to the message middleware, or external third-party systems (e.g., Kafka, MQTT, RabbitMQ, Spark, AWS services, etc.)
Simple summary: in any event can be used to receive, from the device may be, device life cycle events, REST API event, the RPC requests, incoming; capable of processing a single incoming messages and generate one or more outgoing messages sent to different message routing rules for processing the link, while the filter, enrich, to convert the incoming message, or communicate with an external system to perform operations.

Third, the composition of which of the rules engine parts?

1. Regulation message (Message)

Action: means for receiving any event, may be passed from the device, device life cycle events, REST API event, the RPC requests, the
characteristics: there may be a predetermined sequence of the data structures representing various messages in the system
message composition: message ID (MessageId), Universally unique identifier time basis; message originator (originator of the message), Device , Asset or other Entity identifier; message type (type of the message), or telemetry event inactive ; message payload (payload of the message), json packet with the actual message payload; metadata (metadata), lists, and other information related to the key-value pairs of data.
Message Type: The type too many to enumerate. If necessary, please private letter. Free document sharing.
image.png

2. Rules Node (Rule Node)

What is? Rules node is an essential component of the rule engine, it is a single handle incoming messages and generate one or more outgoing messages. Rule node is the primary logical unit of the rules engine. Rules node may be filtered, enrich, to convert the incoming message, or communicate with an external system to perform operations.
Action: filtering rules node may be rich, to convert the incoming message, or communicate with an external system to perform operations. Ability to customize the offering node, implemented computed data.
The relationship between nodes: rule node may be associated with other rules node. Each relationship has a relationship type, which is used to identify the logical meaning of the relationship between the labels. When the outgoing message generation rules node, it is always designated for routing messages to the next node of the relationship type.
Rules node types:
A, filter node (for message filtering and routing, filtering chain success go really wrong to go fake chain). Example 1: script (script filter node) using javascript message filtering conditions (message msg, metadata message metadata, msgType message type); Example 2: switch (switching node) routes the incoming message to one or more output chain node configured to perform JavaScript function.
Filter node:
image.png

b, set node attributes: means for updating the metadata of the incoming message. Example 1: message originator user attributes (customer attributes), the originator of the message attribute information or telemetry data Metadata added metadata. Example 2: Device attributes (device attributes), the device attributes or telemetry data message originator added metadata.
Attribute set node:
image.png

C, transform node: the user changes the field created message, for example, the initiator, the type of the payload, metadata. Example 1: Script switching nodes (Script), the role of: modifying the contents of the message (MSG (message payload), msgType (message type), Metadata (Metadata)), increase, can be changed. 2 For example: conversion to the Email node (to email), filled by using the value derived from the email message field data element, converts the message to an email message. Settings "the SEND_EMAIL" output message types, can be accepted after the "Email node." All E-mail field value can be configured to use metadata.
image.png

d, action node: performing various actions according to the incoming message. Example 1: create alarm (alarm created), on the condition of an alarm message is triggered by the filter is determined after filtering script nodes. Example 2: log (log created), the system for critical system log output, such as 3: rpc call request (remote RPC call), the monitoring system rpc request, delivers a control command request.
image.png

E, external node: providing the message and routing data to an external middleware, or other third station Fangyun Ping. Used to interact with external systems. Examples 1: kafka (kafka messaging middleware), MQTT (external MQTT agent), RabbitMQ, support will publish data system to kafka / MQTT Agent / RabbitMQ, a consumer subscription for third-party data. Example 2: send email (send messages to external). Examples 3: aws sns: to publish a message to aws sns (Amazon Simple Notification Service message, a publish \ subscribe mode messaging service).
image.png

3. The chain rule (Rule Chain)

What is? Chain rule is a logical set of rules nodes and their relationships. Receiving the outbound message from a node to send it to the next node.
Usage: tenant administrator can define a "root" chain rule, you can define a number of other rules chain. Root chain rule for each incoming message and forwards it to the other chain for additional processing rules. Other rules chain can also forward messages to different rules chain.

Fourth, the use of features

Configuration of the drag and drop layout editing
each node may have a specific rule depending on the configuration parameters of the rules node implemented. For example, "Filter - Script" rule node may be configured to process custom JS function of incoming data.
image.png

Based Commissioning - event pattern rules test
each rule node can be set to debug mode, after enabling, in the event you can view inbound - outbound messages
image.png

JavaScript function test bench
rules of nodes having a particular UI feature that allows users to test JS function. When you click "Test filter function", you will see JS editor, you can use the editor to replace the input parameters and verify the output of the function.
image.png

Rules node can be customized:
if thingsboard existing rules processing nodes, can not handle some customized business scenarios, such as: data for statistical classification, or packet statistics, or push data to external ecological Hadoop to store, or to a specified period time data generated file export, pushed to the small scene based on the remote server, it can be implemented by custom rules node. Official reserves the connection extension development, it is easy to build your own processing logic.

5. Summary:

The basic concept for the use of thingsboard rules engine, the ability to make up the rules engine can be used, and each node of the rules, the rules of the use of the characteristics of the model made a brief introduction. We believe that through this explanation for the basis of the rules engine capacity usage have a rough idea, specific rules engine to explain the actual planning after the device was associated access, and then demonstration. Thank you browse, hope you continue to focus, to support the original, the better the achievements of their own!

Thank the author: 30-year-old farmer uncle code counterattack remember

===================================
source of: 30-year-old farmer uncle code counterattack remember from IoTSchool community "rice child" organize users.
Link: https: //www.iotschool.com/article/34.html
Here Insert Picture Description

Published 11 original articles · won praise 0 · Views 1117

Guess you like

Origin blog.csdn.net/IoTSchool/article/details/104453611