Siddhi 4.0.0 Early Access

Siddhi 4.0.0 is being developed using Java 8 with major core level changes and features. One of the fundamental change to note is that some features of Siddhi have been moved as external extensions to Siddhi and WSO2 Complex Event Processor. This tutorial shows you, how to migrate the complex event project developed using Siddhi 3.x to Siddhi 4.x. Take the sample project developed in "Complex Event Processing - An Introduction" article which was developed using Siddhi 3.1.0.

Warning: Still, Siddhi 4.0.0 is not production ready and it is not recommended to use it until officially released by WSO2.

Required Tools:
  • Git
  • Apache Maven
  • Java 1.8
  • Eclipse or IntelliJ IDEA

Since Siddhi 4.0.0 is not officially released yet, we are going to compile the Siddhi 4.0.0-SNAPSHOT version manually.

Step 1:
Clone the Siddhi project using the following command
git clone

Step 2:
Set the following environment variable to avoid the Maven OutOfMemoryError.
MAVEN_OPTS="-Xms768m -Xmx3072m -XX:MaxPermSize=1200m"

Step 3:
Open the terminal in the siddhi directory and execute the following command to build Siddhi.
mvn clean install

You can reduce the time to build by skipping the tests using the following command
mvn clean install -Dmaven.test.skip=true

The external unique time batch window used in the "Complex Event Processing - An Introduction" is no more available in the Siddhi core. Most of the features are moved to a separate GitHub account known as "wso2-extensions". The external unique time batch window is available under the siddhi-execution-unique. Follow the steps to clone and build the unique extension.

Step 1:
Clone the siddhi-execution-unique project using the following command.
git clone

Step 2:
Open the terminal in the siddhi-execution-unique directory and execute the following command to build Siddhi.
mvn clean install

You can reduce the time to build by skipping the tests using the following command
mvn clean install -Dmaven.test.skip=true

Now clone the siddhidemo project which is from the Complex Event Processing - An Introduction" article or create a new project similar to that as suggested in that article.

Step 1:
Create a new Maven project in Eclipse using the following information.
Group Id: com.javahelps
Artifact Id: siddhimigrationdemo

Step 2:
Add the following dependencies to the pom.xml. Compared to Siddhi 3.x project, siddhi-execution-unique is required in addition.

Note: Check the pom file of Siddhi and siddhi-execution-unique projects and use the same versions in the following properties tag.

    <!--Siddhi -->

Step 3:
Create a new package com.javahelps.siddhimigrationdemo.

Step 4:
Create the as shown below. If you compare this class with the one used in Siddhi 3.x project, the way to use external time batch window is different. In Siddhi 3.x, the external time batch window is referred as #window.uniqueExternalTimeBatch but based on Siddhi 4.0.0 and the unique extension, it must be referred as #window.unique:externalTimeBatch.
package com.javahelps.siddhimigrationdemo;

import java.util.Random;

import org.wso2.siddhi.core.ExecutionPlanRuntime;
import org.wso2.siddhi.core.SiddhiManager;
import org.wso2.siddhi.core.event.Event;

public class Main {
    //    SiddhiDe
    private static final String[] CUSTOMERS = {"Alice", "Barby", "Carol", "Diana"};
    private static final String[] ITEMS = {"Cocoa-Butter Lotion", "Purse-XL", "Purse-L", "Beer", "Biscuit",
            "Chocolate", "ZMA"};
    private static final Random RANDOM = new Random();

    public static void main(String[] args) throws InterruptedException {
        SiddhiManager siddhiManager = new SiddhiManager();

        String streams = "define stream purchaseStream (customerName string, item string, timestamp long); ";
        String query = "partition with (customerName of purchaseStream) " +
                "begin " +
                "from purchaseStream[item == 'Cocoa-Butter Lotion' OR item == 'Purse-XL' OR item == 'ZMA']#window" +
                ".unique:externalTimeBatch(item, timestamp, 500 milliseconds) " +
                "select customerName, convert(count(item), 'double') / 3.0 * 100.0 as noOfPurchases insert into " +
                "possiblePregnant; " +
                "end ";

        // Create ExecutionPlanRuntime using stream definition and query
        ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(streams + query);

        try {
            // Receive the output events
            executionPlanRuntime.addCallback("possiblePregnant", new StreamCallback() {
                public void receive(Event[] events) {
                    String output = String.format("\t\t\t%s is pregnant with %.2f%% confidence.", events[0].getData(0),

            // Send input events
            InputHandler purchaseStream = executionPlanRuntime.getInputHandler("purchaseStream");
            for (int i = 0; i < 1000; i++) {
                Object[] event = generateEvent();
                Thread.sleep(10); // Delay for 10 milliseconds
        } finally {

    private static Object[] generateEvent() {
        String name = CUSTOMERS[RANDOM.nextInt(CUSTOMERS.length)];
        String item = ITEMS[RANDOM.nextInt(ITEMS.length)];
        long time = System.currentTimeMillis(); // Current time

        System.out.println(name + " buys " + item);
        Object[] event = new Object[]{name, item, time};
        return event;


Save all the changes and run the You will see the same results as the Siddhi 3.x project.

Find the project @ GitHub.
Next Post »

Contact Form


Email *

Message *