Esper综述
- 格式:doc
- 大小:48.00 KB
- 文档页数:4
Esper 综述
一.Esper简介
1.典型应用:
• 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)
2.主要技术要求:
• 高吞吐量:能处理大量数据(每秒1000到100K个消息);
• 低延迟:能处理实时或接近实时数据(延迟在几毫秒到几秒);
• 复杂计算能力:检测事件模式,过滤事件,结合事件时间窗或长度窗,连接事件流,基于事件触发等。
3.Esper与关系数据库,Esper引擎
• Esper处理数据的速度远高于传统关系数据库的查询速度,因而内存数据库更适合,但其对实时数据处理不是很理想。
• Esper引擎与数据库相反,数据库存储的是数据,用查询提取数据,而Esper引擎存储的是查询,数据去匹配查询(而不做存储)。
• Esper提供2种处理事件的机制:事件模式(event patterns)和事件流查询(event
stream queries,采用EPL语句)。
二.Esper引擎事件处理机制(流程)
1.事件表示(Event Representations)
• 事件是对过去动作或状态改变的一种不可改变的记录,事件属性则是捕获这种状态变化的信息。
(An event is an immutable record of a past occurrence of an action or
state change. Event properties capture the state information for an
event.)
• 事件的表示形式: A. POJOs
B. Key value pairs (java.util.Map)
C. XML Documents
Java Class Description
ng.Object Any Java POJO (plain-old java object) with getter methods
following JavaBean conventions; Legacy Java classes not
following
JavaBean conventions can also serve as events .
java.util.Map Map events are key-values pairs and can also contain objects,
further Map, and arrays thereof.
org.w3c.dom.Node XML document object model (DOM).
org.apache.axiom.om.OMDocument or OMElement XML - Streaming API for XML (StAX) - Apache Axiom
(provided by EsperIO package).
Application classes Plug-in event representation via the extension API.
• 事件属性:
Type Description Syntax Example
Simple A property that has a single value that
may be retrieved. name sensorId
Indexed An indexed property stores an ordered
collection of objects (all of the same
type) that can be individually
accessed
by an integer-valued, non-negative
index
(or subscript). name[index] sensor[0]
Mapped A mapped property stores a keyed
collection
of objects (all of the same type). name('key') sensor('light')
Nested A nested property is a property that
lives
within another property of an event. name.nestedname sensor.value
2.API Overview
• EPServiceProvider
• Acts as Engine
• EPStatement
• Queries written in EQL
• UpdateListener
3.Esper引擎集成
• Obtain an Esper engine instance
• Create a statement (using the Esper query language)
• Register the statement with the engine
• Create a listener (by implementing a Java interface that will be
triggered when the statement evaluates to true) and attach it to the
statement。
Eg:
//Register events
Configuration configuration = new Configuration();
configuration.addEventType("TempEvent",
BodyTemperatureEvent.class.getName());
// Get Esper CEP Engine
EPServiceProvider cepEngine =
EPServiceProviderManager.getProvider("esper-sportspoc",
configuration);
// Create EPStatement
PlayerBMIStatement playerBMIStatement = new
PlayerBMIStatement(cepEngine.getEPAdministrator());
playerBMIStatement.addListener(new PlayerBMIListener());
// Dispatch Event
cepEngine.getEPRuntime().sendEvent(eventInstance);
三.EPL
四.Event Patterns
Pattern Expression = Pattern atoms + Pattern Operators
Eg:
1) every (spike=ServiceMeasurement(latency>20000) or
error=ServiceMeasurement(success=false))
2) select s from pattern [every s=SubmitOrderEvent ->
(timer:interval(30 sec) and not
OrderAcceptedEvent(theOrder.id=s.theOrder.id))]