On April 19th, AMIS organized a BYOL session (bring your own laptop) on Complex Event Processing. This session was a combination of lecture and demo, some discussion and handson by participants on their own laptops using a virtual machine handed out by the instructor. This session was intended to the audience going with CEP – help them over the initial threshold and get a good understanding for when CEP might come in useful, how it can be applied and how (simple) CQL queries can be constructed to tackle real world challenges.
The Virtual Machine that was used contained the Oracle CEP 11R1 PS3 release – Eclipse with CEP plugin as IDE and the CEP Server – and was quite light weight. The instructions below were used in the context of that machine – and start right after the installation of the CEP environment is complete. You can use these same instructions to also get going with CEP. Good Luck!
Run the Oracle CEP IDE (Eclipse plus plug in) by clicking the short cut on the desktop or using the appropriate option on the start menu:
Eclipse will open – after some start up time.
Creating a default CEP application
You will now create your first – HelloWorld – CEP application. Then you will run it and see the world’s simplest event processing in action.
1. From the New icon, open the dropdown menu and select the option Project.
Select the project type Oracle CEP Application Project under Oracle CEP:
and press Next.
2. Configure the new CEP project. Type HelloWorld as the name of the project:
Press Next.
Accept the default settings on the page Oracle CEP Application Content.
Press Next.
Check the checkbox “Create an Oracle CEP Application using an application template” and select the HelloWorld template:
Press Finish.
A new project is now generated for you.
3. Inspect the resources that have been generated. Which file defines the EPN (Event Processing Network)? Where is the CQL statement that is executed by the helloworldProcessor? Where do the events come from that this application processes?
Deploy and Run default application
You will now run the default application and see what is can do (which is frankly not very much yet).
1. Click on the Oracle CEP v11.1 at localhost Server in the Servers window. From the context menu, select the option Add and Remove.
The Add and Remove Window opens.
2. Select the HelloWorld application in the list of available applications and click on the Add button:
Press Finish.
3. Start the CEP Server:
4. The HelloWorld application should start to run. The console will display output similar to this:
If the application does not run immediately, then right click it and select Force Publish from the context menu.
This option can also be used to deploy changes you have wrought in the application to the server while it is already running.
Enhance the default application’s functionality (a little bit)
You will now start extending the CQL query a little to scratch the surface of what CQL is capable of.
1. Double click on the helloworldProcessor in the EPN.
This will open file config.xml which contains the CQL statement.
2. The events that are currently produced by the helloworldProcessor contain a string property – message – that contains the current time. Multiple events are generated every second and all of them are currently passed onwards by the helloWorldProcessor.
Your first task is to only pass on events generated at 0, 5, 10, 15, … seconds into the minute. You can make use of the CQL LIKE operator that accepts a regular expression to search (and filter) on.
Add a where clause to the CQL statement, that specifies the appropriate condition on event property message:
where message like “[0|5] [A|P]M$”
To redeploy the application, click on HelloWorld in the Servers window. Right click and select Force Publish from the context menu:
The Console will now display far fewer messages, and only with 0, 5, 10, 15 … seconds:
3. One thing CEP through CQL is quite good at is aggregation. Let’s count the number of messages (produced at 0, 5, 10, 15,… seconds).
To that end, change the select * in the CQL query to:
select ‘Number of qualifying messages thusfar ‘||count(*) as message
Force Publish the HelloWorld application, and see the new results:
4. We do not necessarily need a report of the total number of messages from the start of the application whenever a new message is produced. It would be quite alright to only have an update on the total number once every 10 seconds. CQL has an easy way of expressing that requirements, using the SLIDE operator.
Change the from helloworldInputChannel into:
from helloworldInputChannel [range 1 day slide 10]
Force (re)publish the application and see the effect: far fewer messages, showing aggregate results:
5. Instead of counting all events for the last day (range 1 day) we can also count the events in the last 30 seconds and produce a result every 10 seconds. Given the event producing logic, we would expect the same number of messages in every 30 second period. Let’s see if that really is the case.
Change the from clause again, into:
from helloworldInputChannel [range 30 second slide 10]
Force republish the application and monitor the console.
Can you explain the first three results?
Chaining processors and wiring channels
Suppose we would like to continue producing events every 10 seconds with an aggregate over the last 30 seconds, and also produce a result every 40 seconds with the number of messages produced by the helloworldProcessor in the last 40 seconds. Regardless of the value of this requirement – let’s implement it. And we do so using a second processor and a second channel.
1. Right click on the EPN diagram and from the context menu select New | Processor.
Set the name for the processor:
Press OK.
2. Right click the EPN diagram again, this time to add a Channel:
Right click the new channel and select the option Rename.
Change the name of the new channel into resultCountEventChannel
3. Double click the resultCountEventChannel. In the assembly source (file helloworld-context.xml) type the event-type attribute for the channel, to indicate what type of event will flow over this channel:
event-type=”HelloWorldEvent”
The underlying EPN Assembly file contains:
4. Wire the helloworldOutputChannel to the countResultsProcessor.
Wire this processor to the new resultCountEventChannel and wire the channel to the HelloWorldBean.
5. Double click the countResultsProcessor to specify its CQL statement.
Set the CQL query to:
select ‘Results in last 40 seconds ‘||count(*) as message
from helloworldOutputChannel [range 40 second slide 40 second]
6. Force Publish the application again. Watch the output.