...
Access the Stream Processor Studio via the
http://<HOST_NAME>:<EDITOR_PORT>/editor
URL.Info The default URL is
http://localhost:9390/editor
The Stream Processor Studio opens as shown below.
Enter a name for your Siddhi application. In this scenario, let's name the application
CargoWeightApp
as shown below.Code Block language sql @App:name("CargoWeightApp")
Defining the input stream. The stream needs to have a name and a schema defining the data that each incoming event should contain. The event data attributes are expressed as name and type pairs. In this example:
The name of the input stream:
CargoStream
A name to refer to the data in each event:
weight
Type of the data received as weight:
int
Code Block language sql define stream CargoStream (weight int);
Define an output stream. This has the same info as the previous definition with an additional
totalWeight
attribute that contains the total weight calculated so far. Here, we need to add asink
configuration to log the events from theOutputStream
so that we can observe the output values.Info A sink specifies the method of publishing streams to external systems via Siddhi. In this scenario, the sink added is of the
log
type, and it publishes output streams as logs in the CLI.Code Block language sql @sink(type='log', prefix='LOGGER') define stream OutputStream(weight int, totalWeight long);
- Enter a Siddhi query that defines the following.
- A name for the query (i.e.,
cargoWeightQuery
) - The input stream from which the events to be processed are taken (i.e.,
CargoStream
) - The data that needs to be sent to the output stream (i.e.,
weight
andtotalWeight
) - How the output needs to be calculated (i.e., by calculating the sum of the weight of all the events)
- The stream to which the output needs to be sent (i.e.,
OutputStream
)
This query is as follows:Code Block language sql @info(name='CargoWeightQuery') from CargoStream select weight, sum(weight) as totalWeight insert into OutputStream;
The completed Siddhi file is as follows:
Code Block language sql @App:name("CargoWeightApp") define stream CargoStream (weight int); @sink(type='log', prefix='LOGGER') define stream OutputStream(weight int, totalWeight long); @info(name='CargoWeightQuery') from CargoStream select weight, sum(weight) as totalWeight insert into OutputStream;
- A name for the query (i.e.,
- To save the Siddhi file, click File => Save. This opens the Save to Workspace dialog box. Click Save to save this file in the
<SP_HOME>/wso2/editor/deployment/workspace
directory (which is the default location where Siddhi applications are saved).
Step 2: Simulate events
...