Creating a Simple Siddhi Application
Introduction
The first tutorial introduces you to WSO2 SP and explains some of its basic concepts.
For this tutorial, let's consider a scenario where Sam, the foreman of the Sweet Factory wants a name-wise total for all the categories of sweets produced until now. During a given run, each Sweet Bot in the factory produces a batch of sweets and generates an event that contains information about the name of the sweet it produced and the quantity produced.
Individual events generated by four different worker Sweet Bots are as follows:
Input Event | Sweet Bot No | Item | Quantity |
---|---|---|---|
1 | 1 | Toffee | 11 |
2 | 2 | Gateau | 2 |
3 | 3 | Gingerbread | 5 |
4 | 4 | Gateau | 8 |
The foreman expects to receive the following output from WSO2 SP if the above events are sent in the given order.
Output Event | Item | Quantity |
---|---|---|
1 | Toffee | 11 |
2 | Gateau | 2 |
3 | Gingerbread | 5 |
4 | Gateau | 10 |
This tutorial shows how this data is processed to generate the expected output if it is sent to WSO2 SP to be analyzed.
Before you begin:
- Install Oracle Java SE Development Kit (JDK) version 1.8* and set the
JAVA_HOME
environment variable. - Download the WSO2 SP.
Tutorial steps
The Siddhi application required for this scenario can be created in two methods:
- The Source View of WSO2 Sream Processor Studio where you can write the application in Siddhi Query Language.
- The Design View of WSO2 Stream Processor where you can design the Siddhi application in a graphical interface by dragging and dropping Siddhi components and linking them as required.
Click on the relevant tab to create the Siddhi application in the preferred interface.
Generating the output
Let's see how the Siddhi application you created functions when it is deployed and run in WSO2 SP. For the purpose of learning, the following four events generated by the Sweet Bots are simulated in WSO2 SP via the Event Simulation tool.
To check whether your Siddhi application generates this output, follow the steps below:
- In the Stream Processor Studio, click the following icon for event simulation. This opens the left panel for event simulation.
- In the Single Simulation tab, do the following:
- In the Siddhi App Name field, select SweetTotalApp.
- In the Stream Name field, select SweetProductionStream.
- In the name field, enter
Toffee
. - In the amount field, enter
11
. - Click Start and Send. This will start the siddhi app in run mode and send the event. The following is logged in the console.
Repeat these substeps to send three more events. Change the value for the name and amount fields as follows.
name amount Gateau
2
Gingerbread
5
Gateau
8
The resulting output events should be logged as follows.