Writing a sample program in Siddhi

Creating a new Siddhi project

  1. Go to File -> New -> Project. Select Siddhi project type and click Next button.

alt text

  1. In the next step, we are prompted to select a SDK for the project. If you haven’t already added a SDK, please follow Setting up Siddhi SDK documentation to add a new SDK.

    Select the SDK and click Next button.

alt text

  1. Update the project name and the location and click Next button.

alt text

Now you have successfully created a new Siddhi project.

alt text

Creating a new Siddhi file

  1. Right click on the project and select New -> Siddhi File.

alt text

  1. Enter the file name and click OK button. This will create a new file with the default app annotation.

alt text

Now you should have a new Siddhi file with the default app annotation.

alt text

Running Siddhi files

  1. Write a sample siddhi program as shown in below.

alt text

  1. Write a event input file(input.txt) as shown in below.

alt text

NOTE: You don’t need to define an input.txt file, if you are getting events through an extension.

  1. Select Edit Configurations from the toolbar.

alt text

  1. Click + button and select Siddhi to add a siddhi run/debug configuration.

alt text

  1. Provide a name for the configuration and select the siddhi file from the file chooser.

alt text

  1. Select the event input file from the file chooser and click OK.

alt text

NOTE: You don’t need to select an input.txt file, if you are getting events through an extension.

Near the main function, in the gutter area, Run icon can be found.

  1. Select Run command. This will run the Siddhi file.

alt text

  1. The output will be shown in the Run window.

alt text

Debugging Siddhi files

NOTE: You don’t need to define an input.txt file, if you are getting events through an extension.

  1. Add breakpoints as shown in below and select Debug command. This will start the debug process.

alt text

NOTE Siddhi only allows to add breakpoints on the beginning of a query input section or on the beginning of a query output.

  1. The output will be shown in the Debug window.

alt text


Go to Home: Home