This section explains how to embed WSO2 Siddhi 3.0 in a Java project. This Embedding Siddhi in a Java project allows you to use the Siddhi query language to carry out real time processing on complex events without running a WSO2 CEP server. This is useful when you need to carry out complex event processing in embedded devices in which WSO2 CEP cannot be deployed.
Follow the procedure below to use Siddhi 3.0 as a library.
Table of Contents | ||||
---|---|---|---|---|
|
Step 1: Creating a
...
Java project
Create a Java project using Maven and include the following dependencies in its
pom.xml
file.Code Block language xml <dependency> <groupId>org.wso2.siddhi</groupId> <artifactId>siddhi-core</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>org.wso2.siddhi</groupId> <artifactId>siddhi-query-api</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>org.wso2.siddhi</groupId> <artifactId>siddhi-query-compiler</artifactId> <groupId>org.wso2.siddhi</groupId><version>3.0.2</version> </dependency>
Add the following repository configuration to the same file.
Code Block language xml <repositories> <repository> <id>wso2.releases</id> <name>WSO2 internal <artifactId>siddhi-query-compiler</artifactId>Repository</name> <version>3.0.2</version> </dependency><url>http://maven.wso2.org/nexus/content/repositories/releases/</url> <releases> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </releases> </repository> </repositories>
Info You can create the Java project using any method you prefer. The required dependencies can be downloaded from here.
- Create a new Java class in the Maven project.
Define a stream definition as follows. The stream definition defines the format of the incoming events.
Code Block language java String definition = "@config(async = 'true') define stream cseEventStream (symbol string, price float, volume long);";
Define a Siddhi query as follows.
Code Block language java String query = "@info(name = 'query1') from cseEventStream#window.timeBatch(500) select symbol, sum(price) as price, sum(volume) as volume group by symbol insert into outputStream ;";
This Siddhi query stores incoming events for 500 milliseconds, groups them by symbol and calculates the sum for price and volume. Then it inserts the results into a stream named
outputStream
.
...