Friday, December 19, 2014

Sample on using Apache Cassandra with WSO2 CEP

In this post I hope to explain how you can configure WSO2 CEP to store events in Apache Cassandra.This don't intent to describe how you can configure  WSO2 CEP to receive events . Hence, I'm using configurations of sample 0001 and extend it to publish events to Cassandra as well in addition to publishing as WSO2Event*

In this sample,
- CEP receives events as WSO2Events
- Store received events in Cassandra.
For the sake of simplicity there's no any processing done and events are just passed through.

*WSO2Event is a Thrift based format for events supported by WSO2 CEP.

Configuring WSO2 CEP Server

1. Bring up CEP server with sample configuration 0001 by executing following command in <CEP_HOME>/bin,

./ -sn 0001 -Ddisable.cassandra.server.startup=false

By setting disable.cassandra.server.startup=false we bring up the embedded Cassandra in CEP server and event's will be stored in it. But, note that this embedded cassandra is only to be used for testing purposes and it's recommended to DISABLE IN PRODUCTION deployments.

2.  Add an Cassandra output event Adaptor[1] by navigating to "Configure" -> "Output Event Adaptors". Output adaptor is the component which communicate with Cassandra server and carry out the transport.

Note that I have configured the output adaptor to connect to  embedded Cassandra server @ localhost:9160 and used both user name and password as "admin"

3. Create an event formatter using the "CassandraOutoutEventAdaptor" by navigating to "Event Streams" -> "OutFlows"  of stream.  

Event builder is the component which converts the outbound events to a format which can be stored in Cassandra. Here you have to enter keyspace name and column family name to be used when storing events in Cassandra. 

Only 'map' "Output Event Type" can be used with Cassandra, it will map value of each attribute in an event to key value pairs. Please refer [2] for more on map event formatters.

Now you have configured CEP server to store/publish events to Cassandra.

Verifying if it works

To verify if events have really stored in Cassandra server let's use "cassandra-cli".

1. Login to Cassandra server with using user name and password as "admin".

./cassandra-cli -u admin -pw admin

2. Execute the following commands,
USE TestEventKeyspace; 
LIST TestEventColumnFamily; <- Listing all rows in the Keyspace
If events are successfully stored something similar to following should be shown.


[1] - Output cassandra event adaptor - WSO2 CEP Documentation
[2] -