Using an Event Definition to Identify Athletics News Stories
The event definitions are where the magic happens. The event definitions monitor the streams and take action when they find the desired information. Remember, events are just pieces of data; the event definitions are the actual rules being evaluated inside the Event Processor engine. In our case, we want to monitor the SF_Gate_Stories stream as it receives news stories from the San Francisco Chronicle RSS feed. We need to create an event definition to monitor the SF_Gate_Stories stream and identify stories from the Athletics beat writers. Once we identify a story, we will insert it into the Athletics_News stream along with additional writer data that we retrieve from the Writer_Data data provider.
To create a new event definition, complete the following steps:
- Click Edit > New Event Definition from the EPL menu.
- Enter MLB_News as the Namespace and Submit_Athletics_Story as the Name. Click OK.
- In the Event Definition property window, click the Event Definition tab and enter the text in Listing 3.
- Check the Enabled checkbox
- Click File > Save System from the EP Studio menu to save the EPL.
Listing 3. The EPL for the Submit_Athletics_Story Event Definition
ON
MLB_News:SF_Gate_Stories
WHEN
SF_Gate_Stories.Author = 'Susan Slusser' OR SF_Gate_Stories.Author = 'John Shea'
OR SF_Gate_Stories.Author = 'sslusser@sfchronicle.com' OR
SF_Gate_Stories.Author = 'jshea@sfchronicle.com'
THEN
MLB_News:Athletics_News.INSERT(MLB_News:SF_Gate_Stories.Title,
MLB_News:SF_Gate_Stories.Author,MLB_News:SF_Gate_Stories.Category,
MLB_News:SF_Gate_Stories.Description,MLB_News:SF_Gate_Stories.Link,
Writer_Data[SF_Gate_Stories.Author].Email,Writer_Data[SF_Gate_Stories.Author].Blog,
Writer_Data[SF_Gate_Stories.Author].Organization),
PRINT('' + MLB_News:SF_Gate_Stories.Title + ' ' +
Writer_Data[SF_Gate_Stories.Author].Author + ' ' +
Writer_Data[SF_Gate_Stories.Author].Email +' ' +
Writer_Data[SF_Gate_Stories.Author].Organization)
This event definition monitors the SF_Gate_Stories stream. As SF_Gate_Stories receives information, this event will review each new item checking if the author matches any of the writers contained in the Writer_Data data provider. If the event definition finds a matching item, it inserts the news story into the Athletics_News stream.
While inserting a story, the event definition also inserts additional author details from the Write_Data data provider. All that is required is to pass the value of the Author field from the SF_Gate_Stories stream item to the Writer_Data data provider.
Testing the Scenario
With all the pieces in place, once you save your work we are ready to start the EP Server and test our Baseball News Service. You can start the EP server by clicking the Start Server icon available in the Event Processor programs group (Start > Programs > Event Processor). After the server completes its initialization routine, you should click the EP Console icon to open the console in your web browser.
When the console page displays, click the Streams link and then click the Athletics_News Stream. If all goes well, you should see something resembling Figure 4.
 | |
| Figure 4. Athletics News Stories Combined with Author Data. |
Summary
This sample application shows how quickly you can begin to integrate external information sources into your EP applications. By combining disparate sources of information, you can build applications that provide powerful new insights to your information while also pushing the information to your users or other applications.
More Resources