This sample demonstrates how Siddhi engine can be used with Local event broker to receive, process and publish XML messages.
In this sample CEP will receive stock quote information and fire outputs if the last traded amount vary by 2 percent with regards to the average traded price within past 2 minutes.
from allStockQuotesStream#window.time(120000) insert into fastMovingStockQuotesStream symbol,avg(price) as avgPrice, price group by symbol having ((price > (avgPrice*1.02)) or ((avgPrice*0.98)>price ));
Here we will publish events using an web-service client and fired outputs of the bucket will be send to a web-service called FastMovingStockQuoteReceiverService which will receive the events and log then in console.
Following is the configuration used in this sample.
Prerequisites
- Apache Ant to build & deploy the Sample & Service, and to run the client. Refer Installation Prerequisites for instructions to install Apache Ant.
Deploying the configurations
The steps are as follows :
- Install the WSO2 Complex Event Processor, but do not start the server, Refer to the Installation Guide for instructions.
- In a command prompt, switch to the sample directory: <CEP_HOME>/samples/cep-samples
For example, in Linux: cd <CEP_HOME>/samples/cep-samples - From there, type ant deploy-xml,
This will copy the broker-manager-config.xml to <CEP_HOME>/repository/conf directory and the bucket configuration to <CEP_HOME>/repository/deployment/server/cepbuckets directory. - Now start the WSO2 Complex Event Processor. Refer to the Running the Product for instructions.
Deploying receiver service
The steps are as follows :
- In a command prompt, switch to the FastMovingStockQuoteReceiverService services directory: <CEP_HOME>/samples/services/FastMovingStockQuoteReceiverService
For example, in Linux: cd <CEP_HOME>/samples/services/FastMovingStockQuoteReceiverService - From there, type ant, this will deploy the FastMovingStockQuoteReceiverService in CEP itself.
You can follow the server logs to check whether FastMovingStockQuoteReceiverService.arr has been properly deployed.
You will also be able to see the axis2 service in the services list.
Configuring receiver service
We need to Configure the FastMovingStockQuoteReceiverService in order to receive the output events emitted by the bucket under the FastMovingStockQuotes topic. Here we will be creating FastMovingStockQuotes topic in the local broker and subscribe FastMovingStockQuoteReceiverService on that topic.
The steps are as follows :
- Sign In. Enter your user name and password to log on to the Complex Event Processor Management Console.
- Click on "Add" menu item under "Topics" Menu in Manage section of the left panel
- Specify the topic name in the topic input text box, in this case topic name is : "FastMovingStockQuotes" (the output topic) and click on 'Add Topic' button. This will add the topic to the server and you will be directed to the Topic Browser page.
- Once you click on the topic in topic browser page you will be able see four links as in the bellow image. Click in the subscribe link and you will be directed to Subscribe page.
Create subscription with following details. Once you are done click the Subscribe button.
topic : FastMovingStockQuotes (Output topic) subscription mode: Topic only subscription URL : http://localhost:9763/services/FastMovingStockQuoteService/getOMElement expiration Time : select a future date from calender
Once you click on the "Subscribe" button, you will be directed to the Topic Browser page.
You can verify whether you have correctly subscribe to the topic by clicking on "Details" link of that topic in topic browser page.
Once you click on that, you will be directed to the "topic details" page and there you will find all the subscriptions for that topic and its children (in this case it does not exists) and permission on that topic. Apart from that with the publish section, you can publish a test XML message to that topic and check whether your subscription URL has been properly subscribed.
Running the Client
The steps are as follows :
- In a command prompt, switch to the CEP samples directory:<CEP_HOME>/samples/cep-samples
For example, in Linux: cd <CEP_HOME>/samples/cep-samples - From there, type ant xmlStockQuotePublisher
This will send some XML messages that will trigger output.
Observation
You will be able observe filtered events in the server console as bellow.