www.espertech.comDocumentation
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)
The Esper engine was designed to make it easier to build and extend CEP applications.
Please add Esper and dependent jar files 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”.
EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider();
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.
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; } }
engine.getEPAdministrator().getConfiguration().addEventType(PersonEvent.class);
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”.
select name, age from PersonEvent
String epl = "select name, age from PersonEvent"; EPStatement statement = engine.getEPAdministrator().createEPL(epl);
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”.
engine.getEPRuntime().sendEvent(new PersonEvent("Peter", 10));
Name: Peter, Age: 10
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));