www.espertech.comDocumentation
The Esper engine has been developed to address the requirements of applications that analyze and react to events. Some typical examples of applications are:
Business process management and automation (process monitoring, BAM, reporting exceptions)
Finance (algorithmic trading, fraud detection, risk management)
Network and application monitoring (intrusion detection, SLA monitoring)
Sensor network applications (RFID reading, scheduling and control of fabrication lines, air traffic)
What these applications have in common is the requirement to process events (or messages) in real-time or near real-time. This is sometimes referred to as complex event processing (CEP) and event series analysis. Key considerations for these types of applications are throughput, latency and the complexity of the logic required.
High throughput - applications that process large volumes of messages (between 1,000 to 100k messages per second)
Low latency - applications that react in real-time to conditions that occur (from a few milliseconds to a few seconds)
Complex computations - applications that detect patterns among events (event correlation), filter events, aggregate time or length windows of events, join event series, trigger based on absence of events etc.
The Esper engine was designed to make it easier to build and extend CEP applications.
More information on CEP can be found at FAQ.
Please add Esper and dependent jar files to the classpath:
Esper core jar file esper-
version.jar
ANTLR parser jar file antlr-runtime-4.7.jar
CGLIB code generator jar file cglib-nodep-3.2.5.jar
SLF4J logging library slf4j-api-1.7.25.jar
Janino Java compiler (unless disabled via configuration, see below) janino-3.0.7.jar
and commons-compiler-3.0.7.jar
Optionally, for logging using Log4j, please add slf4j-log4j12-1.7.25.jar
and log4j-1.2.17.jar
to the classpath.
Optionally, for using Apache Avro with Esper, please add esper-avro-
version.jar
to the classpath.
The use of the Janino compiler can be disabled by turning off code generation. Please see Chapter 22, Byte Code Generation and Section 15.4.12, “Engine Settings Related to Byte Code Generation and Compilation”.
Your application can obtain an engine instance by calling the getDefaultPovider
static method of the EPServiceProviderManager
class:
EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider();
This example does not provide a Configuration
configuration object and thus the engine instance returned is configured with defaults. The default engine URI, which is simply the name assigned to the engine, is "default"
.
More information about EPServiceProviderManager
can be found at Section 14.2, “The Service Provider Interface” and the JavaDoc.
More information about engine configuration can be found at Chapter 15, Configuration and the JavaDoc.
Your application can register an event type to instruct the engine what the input events look like. When creating EPL statements the engine checks the available event type information to determine that the statement is valid.
This example assumes that there is a Java class PersonEvent
and each instance of the PersonEvent
class is an event. Note that it is not necessary to create classes for each event type, as explained below. Here is the class:
package com.mycompany.myapp; public class PersonEvent { private String name; private int age; public PersonEvent(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } }
Your application can call the addEventType
method that is part of the runtime configuration interface to tell the engine about the PersonEvent
class:
engine.getEPAdministrator().getConfiguration().addEventType(PersonEvent.class);
Upon calling the addEventType
method and passing the PersonEvent
class the engine inspects the class using reflection and determines the event properties.
Because the class has two JavaBean-standard getter-methods the engine determines that a PersonEvent
has two properties: the name
property of type string
and the age
property of type int
.
Now that the PersonEvent
event type is known to the engine, your application can create EPL statements that have PersonEvent
in the from
-clause and EPL can refer to event property names.
Instead of PersonEvent
being a Java class, it could also be an Apache Avro schema or an XML schema or a Map or array of names and properties. The different event representations are discussed at Section 3.5, “Comparing Event Representations”.
Your application can instead pre-configure event types using the Configuration
object, see Section 15.4, “Configuration Items”.
Your application can, instead of calling an API, add event types using EPL with create schema
, see Section 5.15, “Declaring an Event Type: Create Schema”.
The sample EPL for this getting-started section simply selects the name and the age of each arriving person event:
select name, age from PersonEvent
Your application can create an EPL statement using the createEPL
method that is part of the administrative interface.
The API calls are:
String epl = "select name, age from PersonEvent"; EPStatement statement = engine.getEPAdministrator().createEPL(epl);
Upon creating the statement, the engine verifies that PersonEvent
exists since it is listed in the from
-clause.
The engine also verifies that the name
and age
properties are available for the PersonEvent
since they are listed in the select
-clause.
After successful verification, the engine internally adds an entry to an internally-maintained filter index tree structure that ensures that when a PersonEvent
comes in it will be processed by the statement.
Your application can attach a callback to the EPStatement
to receive statement results.
The following callback simply prints name and age:
statement.addListener( (newData, oldData) -> { String name = (String) newData[0].get("name"); int age = (int) newData[0].get("age"); System.out.println("String.format(Name: %s, Age: %d", name, age)); });
More information about creating EPL statements is at Section 14.3.1, “Creating Statements” and Section 16.6, “The Deployment Administrative Interface” and the JavaDoc.
Your application can provide different kinds of callbacks, see Section 14.3.2, “Receiving Statement Results”.
Your application can send events into the engine using the sendEvent
method that is part of the runtime interface:
engine.getEPRuntime().sendEvent(new PersonEvent("Peter", 10));
The output you should see is:
Name: Peter, Age: 10
Upon sending the PersonEvent
event object to the engine, the engine consults the internally-maintainced shared filter index tree structure to determine if any EPL statement is interested in PersonEvent
events.
The EPL statement that was created as part of this example has PersonEvent
in the from
-clause, thus the engine delegates processing of such events to the statement.
The EPL statement obtains the name and age properties by calling the getName
and getAge
methods.
For different event representations and sendEvent
methods please see Section 3.5, “Comparing Event Representations”.
Specialized event senders are explained in Section 14.4.1, “Event Sender”.
For reference, here is the complete code without event class:
EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider(); engine.getEPAdministrator().getConfiguration().addEventType(PersonEvent.class); String epl = "select name, age from PersonEvent"; EPStatement statement = engine.getEPAdministrator().createEPL(epl); statement.addListener( (newData, oldData) -> { String name = (String) newData[0].get("name"); int age = (int) newData[0].get("age"); System.out.println(String.format("Name: %s, Age: %d", name, age)); }); engine.getEPRuntime().sendEvent(new PersonEvent("Peter", 10));
Esper requires the following 3rd-party libraries at runtime:
ANTLR is the parser generator used for parsing and parse tree walking of the pattern and EPL syntax. Credit goes to Terence Parr at http://www.antlr.org. The ANTLR license is a BSD license and is provided in lib/esper_3rdparties.license
. The antlr-runtime
runtime library is required for runtime.
CGLIB is the code generation library for fast method calls, licensed under Apache 2.0 license as provided in lib/esper_3rdparties.license
.
SLF4J is a logging API that can work together with LOG4J and other logging APIs. While SLF4J is required, the LOG4J log component is not required and can be replaced with other loggers. SLF4J is licensed under Apache 2.0 license as provided in lib/esper_3rdparties.license
.
Janino (optional) is a small and fast Java compiler. Esper, in the default configuration, generates code and compiles generated code using Janino. Janino is optional and does not need to be in classpath after your configuration disables code generation. Janino is licensed under 3-clause New BSD License as provided in lib/esper_3rdparties.license
.
Esper requires the following 3rd-party libraries for running the test suite:
JUnit is a great unit testing framework. Its license has also been placed in the lib directory. The library is required for build-time only.
MySQL connector library is used for testing SQL integration and is required for running the automated test suite.