Thursday, May 29, 2014

WSO2 CEP - Samples

Download wso2 CEP version that you need to try out. http://wso2.com/more-downloads/complex-event-processor/
Here I will be using wso2cep-3.1.0


CEP sample one 0001

This sample demonstrates how to filter incoming event attributes and add them to another stream using simple pass-through with WSO2Event adaptor. There is no Siddhi query. It is simple pass through.

1. Start CEP with sample by command of ‘wso2cep-samples.bat -sn <n>’

eg:
\<wso2cep-home>\bin>wso2cep-samples.bat -sn 0001

image

2. To build sample and run it, go to directory '\<wso2cep-home>\samples\consumers\wso2-event\' type ant

[NOTE]

Do not close this terminal there are events to be received

image

3. Open another terminal, go to <cep-home>/samples/producers/service-stats and run ant from there.
ant -Dhost=xxxx -Dport=xxxx -Dusername=xxxx -Dpassword=xxxx -Devents=xx.
eg:

ant -Devents=15

image

Here is output events (consumers cmd) received from the CEP

image

CEP console

image

 

CEP sample two 0002

This sample filte incoming event attributes and add them to a topic using Java Message Service (JMS) adaptor. There is no Siddhi query.

1. Copy below apache-activemq-5.7./lib jars to <wso2cep-home>/repository/components/lib directory

  • activemq-core-5.7.0.jar
  • geronimo-j2ee-management_1.1_spec-1.0.1.jar

2. Copy below jars to <wso2cep-home>/samples/lib

  • activemq-all-5.7.0.jar
  • geronimo-jms_1.1_spec-1.1.1.jar


3. Start ActiveMQ
eg:
apache-activemq-5.7.0\bin>activemq

image

4.Start wso2 CEP with sample configurations. wso2cep-samples.bat -sn 0002

image
5. <wso2cep-home>\samples\consumers\jms>ant topicConsumer -Dtopic=BasicStockQuotes

image

6. To build and run the jms producer, <wso2cep-home>\samples\producers\stock-quote> ant -Devents=7

image

Here is topic consumer console logs, when jms producer are sending events 

image

CEP admin console

image

looking active MQ console ; http://localhost:8161/admin/

image

 

CEP sample three 0102 - Twitter & Stock-Quote Query matching

Here is set up an execution plan with two siddhi queries that monitor the stock exchange. It checks whether the last

  • Traded price of the stock has changed by 2% within the last minute
  • And who tweet about a company within the last minute for more than 10 times

query used as follows:

from AllStockQuotes#window.time(1 min)
select symbol,price, avg(price) as averagePrice
group by symbol
having ((price > averagePrice*1.02) or (averagePrice*0.98 > price ))
insert into FastMovingStockQuotes;

from TwitterFeed#window.time(1 min)
select company as company, sum(wordCount) as words
group by company having (words > 10)
insert into HighFrequentTweets;

from FastMovingStockQuotes#window.time(1 min) as fastMovingStockQuotes
join HighFrequentTweets#window.time(1 min) as highFrequentTweets on fastMovingStockQuotes.symbol==highFrequentTweets.company
select fastMovingStockQuotes.symbol as company, fastMovingStockQuotes.averagePrice as amount, highFrequentTweets.words as words
insert into PredictedStockQuotes;

Think you have run sample 2 and have setup JMS jar in wso2 CEP

1. Start Active MQ before WSO2 CEP

2. Start sample in wso2 cep by, <wso2cep-home>\bin>wso2cep-samples.bat -sn 0102

3. <wso2cep-home>\samples\consumers\generic-log-service>ant -DsampleNo=0102
builds the sample log service and deploys it in the webapps repository that is relevant to the specified sample. The Web service is now able to receive messages sent from the CEP server.

image

4. <wso2cep-home>/samples/producers/twitter-feed and run ant from there. It builds and runs the Wso2Event producer, which sends twitter feed data to the CEP server.

image

5.<wso2cep-home>/samples/producers/stock-quote>ant -Devents=7

image

6. Now run both in same time and here is CEP out put

image

No comments:

Post a Comment