Creating Business Rules
This section explains how to create a business rule. A business rule can be created from a template or from scratch.
Prerequisites
In order to create a business rule from a template, the following prerequisites must be completed:
- Both the Dashboard and Worker runtimes of the Stream Processor server must be started.
- The templates for business rules must be defined in a template group, and must be configured in the
<SP_HOME>/conf/dashboard/deployment.yaml
file. For detailed instructions, see Business Rules Templates.
Creating a business rule from a template
Creating business rules from an existing template allows you to use sources, sinks and filters already defined and assign variable values to process events.
To create a business rule from a template, follow the procedure below:
- Go to
<SP_HOME>
from the terminal and start the Dashboard runtime of WSO2 SP with one of the following commands:- On Windows:
dashboard.bat --run
On Linux/Mac OS: ./
dashboard.sh
- On Windows:
- Start the Worker runtime of WSO2 SP with one of the following commands:
- On Windows:
worker.bat --run
On Linux/Mac OS: ./
worker.sh
- On Windows:
Access the Business Rule Manager via one of the following URLs.
Protocol URL Format Example HTTP http://<SP_HOST>:<HTTP_PORT>/business-rules
http://0.0.0.0:9090/business-rules
HTTPS https://<SP_HOST>:<HTTPS_PORT>/business-rules
https://0.0.0.0:9443/business-rules
The URLs given above are default. If required, you can change the host name (i.e.,
0.0.0.0
) or the web UI application name (i.e.,business-rules
). For instructions, see Changing the Host Name and Context Path of SP Web Applications.
This opens the following:
- Click Create to open the following page.
- Then click From Template to open the Select a Template Group page where the available templates are displayed.
- Click on the template group that contains the required template to create a rule from it. In this example, the rule is created based on a template in the
Sweet Factory
template group that is packed with WSO2 SP by default. Therefore, click Sweet Factory to open this template group. - In the template group, expand the Rule Template list as shown below, and click on the required template. For this example, click Identify Continuous Production Decrease.
- If you want to change the rule template from which you want to create the rule, select the required value for the Rule Template field.
- Enter a name for the business rule in the Business Rule Name field.
Enter values for the rest of the fields following the instructions in the UI.
The fields displayed for the rule differ based on the template selected.
- If you want to save the rule and deploy it later, click Save. If you want to deploy the rule immediately, click Save and Deploy.
Creating a business rule from scratch
Creating a rule from scratch allows you to define the filter logic for the rule at the time of creating instead of using the filter logic already defined in a template. However, you can select the required source and sink configurations from an existing template.
To create a business rule from scratch, follow the procedure below:
- Start the Dashboard Portal of WSO2 SP with one of the following commands:
- On Windows:
dashboard.bat --run
On Linux/Mac OS:
sh dashboard.sh
- On Windows:
- Start the Worker runtime of WSO2 SP with one of the following commands:
- On Windows:
worker.bat --run
On Linux/Mac OS:
./worker.sh
- On Windows:
Access the Business Rule Manager via one of the following URLs.
Protocol URL Format Example HTTP http://<SP_HOST>:<HTTP_PORT>/business-rules
http://0.0.0.0:9090/business-rules
HTTPS https://<SP_HOST>:<HTTPS_PORT>/business-rules
https://0.0.0.0:9443/business-rules
The URLs given above are default. If required, you can change the host name (i.e.,
0.0.0.0
) or the web UI application name (i.e.,business-rules
). For instructions, see Changing the Host Name and Context Path of SP Web Applications.This opens the following:
- Click Create to open the following page, and then click From Scratch.
- This opens the Select a Template Group page where the available template groups are displayed as shown in the example below.
- Click on the template group from which you want to select the required sources and sinks for your business rule. For this example, click Stock Exchange to open that template group as shown below.
- Click Input to expand the Input section. Then select the rule template from which the source and input configurations for the business rule must be selected.
This displays the list of available sources and the exposed attributes of the selected template as shown below. - Click Filters to expand the Filters section, and click + to add a new filter. A table is displayed as shown below.
- To define a filter, follow the steps below:
- In the Attribute field, select the attribute based on which you want to define the filter condition.
- In the Operator field, select an operator.
- In the Value/Attribute field, enter the value or the attribute based on which the operator is applied to the attribute you selected in step a.
e.g., If you want to filter events where the price is less than 100, select values for the fields as follows:
Field Value Attribute price
Operator <
Value/Attribute 100
Once you have defined two or more filters, enter the rule logic in the Rule Logic field usingOR
,AND
andNOT
conditions. The examples of how you can use these keywords are explained in the table below.Keyword Example OR
1 OR 2
returns events that match either filter 1 or 2.AND
1 AND 2
returns events that match both filters 1 and 2.NOT
NOT 1
returns events that do not match filter 1. - Click Output to expand the Output section. Then select the rule template from which the sink and output connfigurations for the business rule must be selected.
This displays the section for mapping configurations as shown in the example below. Select the relevant attribute names for the Input column. When publishing the events to which the rule is applied via the selected predefined sink, each input event you select is published with the corresponding name in the Output column.
The output mappings displayed differ based on the output rule template you select.
If you want to save the rule and deploy it later, click Save. If you want to deploy the rule immediately, click Save and Deploy.