First steps with Oracle Complex Event Processing (tutorial from AMIS BYOL session)

Lucas Jellema

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:

Image

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.
Image

 

Select the project type Oracle CEP Application Project under Oracle CEP:

Image

 

and press Next.

2. Configure the new CEP project. Type HelloWorld as the name of the project:

Image

Press Next.
Image

 

Accept the default settings on the page Oracle CEP Application Content.

Press Next.

Image

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.
Image

 

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.

Image

The Add and Remove Window opens.

2. Select the HelloWorld application in the list of available applications and click on the Add button:

Image

Press Finish.
Image

 

3. Start the CEP Server:

Image

4. The HelloWorld application should start to run. The console will display output similar to this:

Image

 

If the application does not run immediately, then right click it and select Force Publish from the context menu.
Image

 

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.

Image

This will open file config.xml which contains the CQL statement.

Image

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$”

Image

 

To redeploy the application, click on HelloWorld in the Servers window. Right click and select Force Publish from the context menu:

Image

The Console will now display far fewer messages, and only with 0, 5, 10, 15 … seconds:

Image

 

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

Image

Force Publish the HelloWorld application, and see the new results:
Image

 

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]

Image

Force (re)publish the application and see the effect: far fewer messages, showing aggregate results:

Image

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]

Image

Force republish the application and monitor the console.

Image

 

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.

Image

Set the name for the processor:

Image

 

Press OK.

2. Right click the EPN diagram again, this time to add a Channel:

Image

Right click the new channel and select the option Rename.

Image

Change the name of the new channel into resultCountEventChannel

Image

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:

Image

4. Wire the helloworldOutputChannel to the countResultsProcessor.

Image

 

Wire this processor to the new resultCountEventChannel and wire the channel to the HelloWorldBean.

Image

 

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.

Image

Next Post

Getting started with your career (in Dutch)

Facebook0TwitterLinkedinAls bezoeker van deze blog ben je bezig met het maken van mooie oplossingen en nieuwe uitdagingen op technisch gebied. AMIS nodigt je uit om ons team te komen versterken. AMIS wil je op het gebied van Oracle en Java uitdagen de volgende stap in je carriĆ«re nemen. AMIS merkt […]