Creating a Siddhi Application
Siddhi applications are files that define the Siddhi logic to process the events sent to WSO2 SP. They are written in the Siddhi Query Language using the Stream Processor Studio tool shipped with WSO2 SP.
A Siddhi file contains the following configurations:
Configuration | Description |
|---|---|
Stream | A logical series of events ordered in time with a uniquely identifiable name, and set of defined attributes with specific data types defining its schema. |
Source | This consumes data from external sources (such as |
Sink | This takes events arriving at a stream, maps them to a predefined data format (such as |
Executional Element | An executional element can be one of the following:
|
Creating a Siddhi application
To create a Siddhi application, follow the steps below:
Start WSO2 SP in the editor mode and access the Stream Processor Studio. For detailed instructions, see Starting Stream Processor Studio. The Stream Processor Studio opens as shown below.
Click New to start defining a new Siddhi application. A new file opens as shown below.
Add the following sample Siddhi application to the file.
@App:name("SweetProductionAnalysis") @Source(type = 'tcp', context='SweetProductionData', @map(type='binary')) define stream SweetProductionStream (name string, amount double); @sink(type='log', @map(type='json')) define stream ProductionAlertStream (name string, amount double); from SweetProductionStream select * insert into ProductionAlertStream;To save this Siddhi application, click File, and then click Save. By default siddhi applications are saved in the
<SP_HOME>/wso2/editor/deployment/workspacedirectory.To export the Siddhi application to your preferred location, click File, and then click Export File.