com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_link3' is unknown.

Sample 0102 - Twitter & Stock-Quote Analyzer

Introduction

This sample demonstrates how to 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.

The query used in this sample is 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;
  

It has two incoming streams:

  • Event stream of Stock Quotes from a stock exchange
  • Event stream of word counts of various company names taken from twitter pages

Prerequisites

  1. See Prerequisites in CEP Samples Setup page.
  2. Copy the ActiveMQ JMS related JARs referred in JMS Transport to <CEP_HOME>/repository/components/lib directory.
  3. Copy the following JARs from ActiveMQ distribution directory to <CEP_HOME>/samples/lib directory.
    • <ActiveMQ_HOME>/activemq-all-5.7.0.jar

    • <ActiveMQ_HOME>/lib/ geronimo-jms_1.1_spec-1.1.1.jar

    Start the ActiveMQ server before the CEP server starts.

Building the sample

Start the WSO2 CEP server with the sample configuration numbered 0102. For instructions, see Starting sample CEP configurations. This sample configuration does the following:

  • Creates <CEP_HOME>/repository/conf/stream-manager-config.xml file, which is used to create the stream definitions for the sample.
  • Points the default Axis2 repo to <CEP_HOME>/sample/artifacts/0102 (by default, the Axis2 repo is <CEP_HOME>/repository/deployment/server).

Executing the sample

  1. Open a terminal, go to <CEP_HOME>/samples/consumers/log-service and run the command below:

    ant -DsampleNo=0102

    It builds the axis2 sample log service and deploys it in the axis2 repository that is relevant to the specified sample. The Web service is now able to receive messages sent from the CEP server.

  2. See the logs in CEP server when LogService.aar is deploying.


    Next, let's create PredictedStockQuotes topic in the local broker and subscribe LogService on that topic to receive output events from the CEP server.

  3. Log in to the CEP management console and click Add menu under the Topics menu. Then, specify the topic name (e.g., PredictedStockQuotes) and click Add Topic.
  4. The Topic Browser page opens. Click in the Subscribe link associated with it.
  5. Create a subscription as follows:

    You can now send events to the CEP. 
  6. Open another terminal, go to <CEP_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.

  7. From this terminal, see the details of the events sent.

    Note

    To configure host, port, username, password and number of events, use -Dhost=xxxx -Dport=xxxx -Dusername=xxxx -Dpassword=xxxx -Devents=xx

    For example : ant

  8. Open another terminal, go to <CEP_HOME>/samples/producers/stock-quote and run ant from there.

    It builds and runs the jms producer, which sends sample stock quotes to the CEP server.

  9. From the terminal opened in the above step, see the details of the events sent. For example,

  10. Also see the console output in the CEP server, when events are received after processing. For example,

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.