...
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> <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 Repository</name> <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
.
...