What is Esper

Eserper is a library that helps you work with Complex Event Processing(CEP). The basic idea is anlyzing a constant flux of event and discover patterns. This is different from Stream Processing which will aggregate, filter and transform a flux of event. You usually use CEP when you want to take action when a certain pattern appear in the events.

Querying your stream

Esper provides the Esper Query Language which is very close to SQL. This is nice as it diminishes the learning curve, however, it hides the fact you have to think about your problem differently. When you query a database using SQL, the database simulate data isn’t changing during the SQL execution. When using Esper, data being queried will constantly change. That’s why you need to think about your problem differently.

How to think about your problem

You need to think of your stream of data as a river with various kind of fishes. What you want is find if certain pattern appear among those fishes. In order to do that, you will need want to isolate the type of fishes you are interested up to the point where it is easy to express the pattern you are looking for as a simple SQL.


Imagine you have a stream of data coming from temperature sensors spread accross your home. When the temperature get below 22 degrees in both the hall and the bedroom, you want to display a warning. When the temperature in those places get below 18 you want to display an alert.

Let’s isolate the places we are interested in

In order to do that we will start creating named windows only containing temperature of hall and bedroom.

Let’s deduce the status of each places

Get the home temperature status

We are almost there. For each room we have the status: ok, warning, alert. Now let’s use an SQL to deduce the status of the home:

You can copy and past the full script below into Esper EPL Online and have fun with it :)

Full script:

Have fun!

comments powered by Disqus