|
| 1 | +--- |
| 2 | +title: Rules Engine |
| 3 | +--- |
| 4 | + |
| 5 | +The **Rules Engine** in Magistrala is a feature that allows users to define, manage, and automate message processing logic. |
| 6 | +It enables the creation of rules that process input data, apply logical conditions, and output results accordingly. |
| 7 | +Users can create rules by attaching input, logic, and output nodes. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Create Rules:** Specify input channel and topic, apply logical conditions, and specify output channel and topic |
| 12 | +- **Update Rules:** Modify existing rules, including input, logic, and output nodes. |
| 13 | +- **Delete Rules:** Remove rules that are no longer needed. |
| 14 | +- **Enable/Disable Rules:** Users can activate or deactivate rules as required. |
| 15 | +- **Comparison Blocks:** Add conditional logic to the rules for evaluating message payloads. |
| 16 | +- **Lua Script Integration:** Users can switch between a comparison block and a Lua script editor to define custom logic. |
| 17 | + |
| 18 | +## **Create a Rule** |
| 19 | + |
| 20 | +To create a **Rule** navigate to the Rules section and click on the `+ Create` button to open the rule creation dialog. Provide a **name** for the rule and click Create. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +Users can view all created rules in a structured list, displaying: |
| 25 | + |
| 26 | +- Rule name |
| 27 | +- Status (Enabled/Disabled) |
| 28 | +- Creation date |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +## **View a Rule** |
| 33 | + |
| 34 | +Click on the rule name present at the rules table to be redirected to the Rule's ID page. |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +From here users can view the Rule's input and output nodes as well as the logic. |
| 39 | + |
| 40 | +## **Updating Rule Status** |
| 41 | + |
| 42 | +Users can enable or diable a Rule by clicking on the Toggle at the top right of the Rule page. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +## **Adding Comparison Block** |
| 47 | + |
| 48 | +A **Comparison Block** allows users to define conditions based on message payloads: |
| 49 | + |
| 50 | +- Example conditions: |
| 51 | + |
| 52 | + - `If temperature is greater than 10` |
| 53 | + - `And temperature is less than 40` |
| 54 | + |
| 55 | +- Users can combine multiple conditions using **AND/OR** operators. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +## **Switching Between Logic Types** |
| 60 | + |
| 61 | +Users can switch between a **Comparison Block** and **Lua Script** editor: |
| 62 | + |
| 63 | +1. Click on the options menu (`...`) in the logic node. |
| 64 | +2. Select `Switch to editor` to enter the Lua script mode. |
| 65 | +3. Enter the custom script for message processing. |
| 66 | +4. Save the changes. |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
0 commit comments