Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. 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.

  2. Enter a name for your Siddhi application. In this scenario, let's name the application CargoWeightApp as shown below.

    Code Block
    languagesql
    @App:name("CargoWeightApp")
  3. 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
    languagesql
    define stream CargoStream (weight int);
  4. 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 a sink configuration to log the events from the OutputStream 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
    languagesql
    @sink(type='log', prefix='LOGGER')
    define stream OutputStream(weight int, totalWeight long);
  5. 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 and totalWeight)
    • 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
    languagesql
    @info(name='CargoWeightQuery')
    from CargoStream
    select weight, sum(weight) as totalWeight
    insert into OutputStream;

    The completed Siddhi file is as follows:

    Code Block
    languagesql
    @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;
  6. 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).
    Image RemovedImage Added

Step 2: Simulate events

...