All docs This doc

Versions Compared

Key

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

...

  1. 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.
  2. Click New to start defining a new Siddhi application. A new file opens as shown below.
  3. To open the design view, click Design View.
  4. To define the input stream into which the events to be processed via the Siddhi application should be received, drag and drop the stream icon (shown below) into the grid.
  5. Click on the settings icon on the stream component you added.

     
    As a result, the Stream Configuration form appears below the grid as shown below.
    Image Modified    
    Fill this form as follows to define a stream named SweetProductionStream with two attributes named name and amount:

    1. In the Name field, enter SweetProductionStream.
    2. In the Attributes table, enter two attributes as follows. You can click +Attribute to add a new row in the table to define a new attribute.

      Attribute NameAttribute Type
      namestring
      amountdouble
    3. Click Submit to save the new stream definition. As a result, the stream is displayed on the grid with the SweetProductionStream label as shown below.
       
  6. To define the output stream to which the processed events need to be directed, drag and drop the stream icon again. Place it after the SweetProductionStream stream. This stream should be named ProductionAlertStream and have the following attributes.

    Attribute NameAttribute Type
    namestring
    totalProductionlong
  7. To add the source from which events are received, drag and drop the source icon (shown below) into the grid.

    As a result, the Source Configuration form appears below the grid. Enter values in this form as follows to configure a source via which events can be received.
    1. In the Name field, enter a name for the source. Then click Save to add the source

      Info

      The name must always be the name of the transport via which the events are received. This must be entered in lower case (e.g., tcp).

    2. To configure the source by entering values for the rest of the parameters, the source must be connected to a stream. This tcp source needs to be connected to the  SweetProductionStream input stream so that the events received via  TCP can be directed there. To connect the source to the stream, draw an arrow from the source to the stream by dragging the cursor as demonstrated below.

      Then open the Source Configuration form again by clicking the Settings icon of the tcp source.
       
    3. Click Properties. Based on the properties you want to configure for the source, select the relevant check box to select the required annotation type. In this example, let's select both Options and Map.

      As a result, the Options and Map sections appear as shown below.

      1. Enter context='SweetProductionData' in the Options field to indicate the context. You can add multiple options by clicking + Option to add more fields under Options.
      2. For this example, assume that events are received in the binary format. To allow this, enter binary in the Name field under Type in the Map section.
      Now the Source Configuration form looks as follows:
       
    4. Click Save to save the source configuration.
  8. To add a query that defines the execution logic, drag and drop the projection query icon (shown below) to the grid.
  9. The query uses the events in the SweetProductionStream input stream as inputs and directs the processed events (which are its output) to the ProductionAlertStream output stream. Therefore, create two connections as demonstrated below.
     
  10. To define the execution logic, move the cursor over the query in the grid, and click on the settings icon that appears.

    This opens the Query Configuration form. Enter information in it as follows:
    1. To specify that the SweetProductionStream stream is the input stream from which the events to be processed are taken, enter it in the Stream/Trigger field in the Input section.
    2. To define how each attribute is processed, enter the following in the User Defined Attributes table.

      ExpressionAsPurpose
      namenameWhen creating the output events, the name attribute is output with the same attribute name.
      sum(amount)amountWith each event that arrives in the SweetProductionStream stream, the query calculates the sum for the amount attribute, and outputs the result with amount as the attribute value.
    3. The output events generated need to be inserted into the ProductionAlertStream output stream. To achieve this, enter information in the Output section as follows:
      1. In the Operation field, select Insert. This value is selected because the output events need to be inserted into the ProductionAlertStream output stream.
      2. In the Into field, enter ProductionAlertStream.
      3. In the For field, select all events.
    4. Click Save to save the entries.
  11. To add a sink to publish the output events that are directed to the ProductionAlertStream output stream, drag and drop the sink icon (shown below) into the grid.
     
    As a result, the Sink Configuration form appears below the grid. Enter values in this form as follows to configure a sink via which events can be published.
    1. In the Name field, enter a name for the sink.

      Info

      The name must always be the name of the transport via which the events are published. This must be entered in lower case (e.g., log ).

    2. Click Properties. Based on the properties you want to configure for the sink, select the relevant check box to select the required annotation type. In this example, assume that the events need to be published in the json format. Therefore, let's select the Map check box, and enter type=json to specify json as the mapping type.

  12. Connect the sink you added to the ProductionAlertStream output stream by dragging and dropping the cursor from the ProductionAlertStream output stream to the sink.
  13. To allign the Siddhi components that you have added to the grid, click Edit and then click Auto-Align. As a result, all the components are horizontally aligned as shown below.
  14. Click Source View. The siddhi application is displayed as follows.
  15. Click File and then click Save as. The Save to Workspace dialog box appears. In the File Name field, enter SweetProductionAnalysis and click Save.
     

...