The following sections walk you through the basic features of the CEP sample to get you started:
Step 1: Downloading the product
- Download the latest version of the CEP as described in Downloading the Product.
- Extract the archive file to a dedicated directory for the CEP, which will hereafter be referred to as <CEP_HOME>.
Step 2: Creating and setting up a MySql database
A mysql database is required to be set up, in order to store events generated in a latter step. Follow the below steps.
Create a new mysql database, named 'testdb'.
mysql> create database testdb; mysql> use testdb;
Create a new table, with the specified attribute-names and data types, as specified in the following command:
mysql> CREATE TABLE delivered_orders (sum_order_id BIGINT, customer_name VARCHAR(20));
Populate the newly created table by executing the following command:
mysql> INSERT INTO delivered_orders (sum_order_id, customer_name) VALUES(1,'Tom'),(2,'John'),(3,'Ratha');
- Download and add mysql JDBC driver to
<CEP_HOME>/repository/components/lib/
directory.
Step 3: Installing and running the CEP Server
Install and run the CEP server as specified in the following documents:
Step 4: Running the data publisher
Open a terminal, go to <CEP_HOME>/samples/producers/pizza-shop and run the following command:
ant pizzaPublisherClient
Running the above command will result in two new stream definitions being created:
- deliveryStream:1.0.0
- orderStream:1.0.0
You may verify this by, going to the management console and navigating to Home > Manage > Event Processor > Event Streams. You will see these two new stream definitions.
Step 5: Adding an execution plan
1. In the Management Console, navigate to Home > Manage > Event Processor > Execution Plans.
2. Click on 'Add Execution Plan'
3. This will show the 'Create new Execution Plan' window.
4. In the Execution Plan Name field, enter “pizaaOrderProcessingPlan”
5. There, under Query Expressions, import both deliveryStream:1.0.0 and orderStream:1.0.0.
To do this,
i. Go to Import Stream drop-down menu and select deliveryStream:1.0.0. In the As: text field, type deliveryStream and click Import.
ii. Go to Import Stream drop-down menu and select orderStream:1.0.0. In the As: text field, type orderStream and click Import.
6. Add the following queries in to the Query Expression field.
define table pizza_deliveries (deliveredTime long, order_id string); from deliveryStream select time, orderNo insert into pizza_deliveries; from orderStream#window.time(30 seconds) insert into overdueDeliveries for expired-events; from overdueDeliveries as overdueStream unidirectional join pizza_deliveries on pizza_deliveries.order_id == overdueStream.orderNo select count(overdueStream.orderNo) as sumOrderId, overdueStream.customerName insert into deliveredOrders;
You can try validating the query expression by clicking on 'Validate Query Expression' button.
6. Now export the deliveredOrders stream.
To do this, under Export Stream section,
i. Insert deliveredOrders into the Value of field.
ii. In the StreamId field, select 'Create Steam Definition'
iii. This will show the Define 'New Event Stream' window.
iv. Click 'Add Event Stream'
v. You will see the 'Stream Definition added successfully' message.
vi. Now you will see a prompt, asking “Defined event streams can publish out flow of events using event formatter. Do you want to create an event formatter now?” Close this pop up, since an event formatter will be created later.
vii. Then select the newly added Stream Definition, that is deliveredOrders from the StreamId field.
viii. Click 'Add' button, which is next to the StreamId field.
7. Click 'Add Execution Plan'.
Step 6: Creating a datasource
In this example, we are inserting attributes in the exported stream into a mysql database. For this purpose, we need to create a reference to an already created database.
- Navigate to Home > Configure > Data Sources
- Click 'Add Data Sources'
- This will show up the 'New Data Source' page.
- Insert the following details:
Data Source Type | RDBMS |
Name | TESTDB_MYSQL_DB |
Data Source Provider | default |
Driver | com.mysql.jdbc.Driver |
URL | jdbc:mysql://localhost:3306/testdb |
User Name | (your mysql username) |
Password | (your mysql password) |
Step 7: Creating an Output Event Adaptor
- Navigate to Home > Configure > Event Processor Configs > Output Event Adaptors
- Click 'Add Output Event Adaptor'
Insert the following details:
Event Adaptor Name
MysqlOutputAdaptor Event Adaptor Type
mysql Data Source Name
TESTDB_MYSQL_DB - Test the connection. 'Connection is successful' message will be displayed upon successful creation of the connection.
- Click 'Add Event Adaptor'
Step 8: Creating an Event Formatter
- Navigate to Home > Manage > Event Processor > Event Streams
- It will show up three available Event Streams.
- Click on the 'Out-Flows' which belong to 'deliveredOrders:1.0.0' Event Stream. See the image below.
- This will show up 'Event Out-Flows' page.
- Click on 'Publish to External Event Stream(via Event Formatter)'
- Insert the following details:
Event Formatter Name | PizzaDeliveryEventFormatter |
Output Event Adaptor Name | MysqlOutputAdaptor |
Table Name | delivered_orders |
Execution Mode | Insert or Update |
Composite key columns | customer_name |
Click on Advanced and insert the following mapping:
Name | Value Of: |
---|---|
sum_order_id | sumOrderId |
customer_name | customerName |
7. Click 'Add Event Formatter'
8. A message will pop up saying 'Event formatter added successfully!!'
Step 9: Publishing data to CEP
Navigate to
<CEP_HOME>/samples/producers/pizza-shop/
directory, and execute the following command:ant pizzaPublisherClient
As this publisher publishes data to the
Adding an execution plan, will get executed. While the execution plan is running, the data created will get exported todeliveryStream
andorderStream
streams, which were defined in Running the data publisher), the execution plan defined indeliveredOrders
stream as specified in Adding an execution plan. When thedeliveredOrders
stream gets populated with data, thedelivered_orders
MySQL table will also get populated, as a result of creating thePizzaDeliveryEventFormatter
in Creating an Event Formatter.
Step 10: Creating the dashboard
After creating the table populated with useful information retrieved from complex event processing in Publishing data to CEP, follow the steps below to create a dashboard to display this data.
1. Navigate to Main > CEP Dashboard
2. This will prompt you to log in to the CEP Dashboard.
3. Insert 'admin' as username and 'admin' as password.
4. Now the CEP Dashboard will be loaded.
5. Click on 'Personalize'
6. Click on 'Create New Gadget'
7. 'Add Gadget' window will load.
8. In the 'Select Data Source' step ,select RDBMS, and click Next.
9.In the 'Configure Data Source' step, select 'TESTDB_MYSQL_DB ', and click Next.
10. Add 'select * from delivered_orders' in the SQL Statement field. Clicking 'Run' will show up the query results. Click Next.
11. In the 'Select a Gadget' step, select 'Bar Chart v1.0.0' and click 'Select Template'. Then click 'Next'.
12. In the last step: 'Preview', insert the following details:
Chart Title | Delivered Orders |
X-Axis Label | Customer Name |
Y-Axis Label | Order Count |
Update Interval | 2 |
Time Series Chart | (leave it unchecked) |
Series Label | (may leave empty) |
X-Axis | customer_name |
Y-Axis | sum_order_id |
Click on Preview. A preview should be displayed with the correct data.
13. Click 'Finish'.
14. The gadget is now inserted in to the CEP Dashboard.