Skip to content

Siddhi 5.1 as a Java library

Siddhi can be used as a library in any Java program (including in OSGi runtimes) just by adding Siddhi and its extension jars as dependencies.

  • Find a sample Siddhi project that's implemented as a Java program using Maven here, this can be used as a reference for any based implementation.

  • Following are the mandatory dependencies that need to be added to the Maven pom.xml file (or to the program classpath).



Sample Java class using Siddhi is as follows.

package io.siddhi.sample;

import io.siddhi.core.SiddhiAppRuntime;
import io.siddhi.core.SiddhiManager;
import io.siddhi.core.event.Event;
import io.siddhi.core.util.EventPrinter;

 * The sample demonstrate how to use Siddhi within another Java program.
 * This sample contains a simple filter query.
public class SimpleFilterSample {

    public static void main(String[] args) throws InterruptedException {

        // Create Siddhi Manager
        SiddhiManager siddhiManager = new SiddhiManager();

        //Siddhi Application
        String siddhiApp = "" +
                "define stream StockStream (symbol string, price float, volume long); " +
                "" +
                "@info(name = 'query1') " +
                "from StockStream[volume < 150] " +
                "select symbol, price " +
                "insert into OutputStream;";

        //Generate runtime
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

        //Adding callback to retrieve output events from stream
        siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
            public void receive(Event[] events) {
                //To convert and print event as a map

        //Get InputHandler to push events into Siddhi
        InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");

        //Start processing

        //Sending events to Siddhi
        inputHandler.send(new Object[]{"IBM", 700f, 100L});
        inputHandler.send(new Object[]{"WSO2", 60.5f, 200L});
        inputHandler.send(new Object[]{"GOOG", 50f, 30L});
        inputHandler.send(new Object[]{"IBM", 76.6f, 400L});
        inputHandler.send(new Object[]{"WSO2", 45.6f, 50L});

        //Shutdown runtime

        //Shutdown Siddhi Manager



Siddhi running as a embedded Java library can be configured with environment specific properties using Extension System Parameters, References, and Siddhi Properties using either InMemoryConfigManager or YAMLConfigManager. Please refer the blog for details.