WSO2 CEP uses Execution Plans to store event processing logic. An Execution Plan is bound to an instance of the Siddhi complex event processing runtime, which is responsible for the actual processing of the events. The event processor allows users to configure multiple Execution Plans where by providing multiple isolated event processing environments per Execution Plan. A typical Execution Plan consists of a set of queries and related input and output Event Streams.
WSO2 CEP 3.x.x versions and above, only support Siddhi runtime and they no longer support Esper / Drools fusion.
Writing an Execution Plan
You will get an execution plan template as shown bellow.
You can edit this template to create a new execution plan. Follow the steps below to edit the template and create a new execution plan.
The execution plan editor supports auto completion.
To view the suggestions made by the editor, press control+space keys together.
The suggestions contain two sets.
- Siddhi keywords, in alphabetical order
- All the other words which are already inserted into the editor. For example, stream names which are defined in step 2 will be suggested when writing the queries in step 3. These will appear in alphabetical order after the keyword list.
In addition to the above, press shift+2 keys together to view suggestions on annotations.
Step 1. Add execution plan info
Add Execution Plan Name:
Give a meaningful name to the execution plan by replacing 'ExecutionPlan' in @Plan:name('ExecutionPlan') with the new name.
For example, if the new name should be 'NewExecutionPlan', then replace @Plan:name('ExecutionPlan') with @Plan:name('NewExecutionPlan').
This is the description of the execution plan. Giving a description is optional.
To give a description to the execution plan,
- uncomment the line "-- @Plan:description('ExecutionPlan')".
- replace 'ExecutionPlan' with the description
For example, @Plan:description('This is the description for my NewExecutionPlan')
Step 2. Import Streams
An execution plan processes one or more streams. Therefore it is mandatory to import streams into an execution plan.
Importing a stream means mapping an available Event Stream to another "internal" stream. This internal stream is then used in query expressions, which will be written in step 3: Add query expressions. In fact, this internal stream is meant to be used by the Siddhi runtime.
To import a stream,
- select an already defined stream from the drop down list which appears next to 'Import Stream: '
- give a meaningful name to the stream in the text box which appears next to 'As:'
This will import an available Event Stream as a new stream.
The form inputs are described as follows:
- Import Stream : The name of the CEP Event Stream which will feed its events to the Execution Plan.
- As : The name to be used when feeding the stream to the Siddhi engine. This can contain only alphanumeric characters and underscore (_).
Step 3. Add query expressions
Contains the event processing logic written in Siddhi query language . When defining more than one query, each query should end with a semi colon.
Step 4. Export streams
Defines the mappings between the exported (output) stream of the Siddhi runtime to one of the available Event Streams (defined inside query expressions). The parameters are as follows:
- Value Of : The name of the stream exposed by the Siddhi runtime. This can contain only alphanumeric characters and underscore (_).
- StreamId : The CEP Event Stream's id to which the output events are sent from the Execution Plan.
- It is not mandatory to define export streams in an execution plan.
- Siddhi Event tables cannot be exposed as streams. Event tables are only considered as streams within Siddhi.
Step 5. Add execution plan
Before adding the execution plan to the Siddhi runtime, it can be validated by clicking on the 'Validate Query Expressions' button.
Finally click the Add Execution Plan button to deploy the Execution plan.
Editing a deployed execution plan
- After an execution plan is successfully created, you can change it and redeploy it as follows.
- Go to Main --> Manage --> Event Processor --> Execution Plans and select the execution plan needs to be edited by clicking on Edit button link associated with it. You can also click other associated links to delete it, enable/disable statistics or enable/disable tracing.
- Edit the execution plan as required, and click Update.
- Alternatively,you can write your execution plan in a text file and save it with the extension '.siddhiql' (which stands for Siddhi Query Language) and drop it in the deployment directory
<PRODUCT_HOME>/repository/deployment/server/executionplans. Since hot deployment is supported you can simply add/remove Execution Plan files to deploy/undeploy Execution Plans from the server.