采用maven项目管理模式
pom配置如下:
代码如下:
pom配置如下:
[color=blue]<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.wolf.esper</groupId>
<artifactId>wolf-esper</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esper</artifactId>
<version>4.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esperio-csv</artifactId>
<version>4.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esperio-db</artifactId>
<version>4.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esperio-http</artifactId>
<version>4.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esperio-socket</artifactId>
<version>4.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esperio-springjms</artifactId>
<version>4.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esperio-stax</artifactId>
<version>4.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>[/color]
代码如下:
package org.wolf.esper;
import org.wolf.esper.event.OrderEvent;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.UpdateListener;
/**
* esper 特性:
* 监听的事件源:包括简单的pojo,http,socket,db等,
* 监听的语法:语法规范类似于sql语法
* @author Administrator
*
*/
[color=green]public class EPServiceProviderMain {
public static void handlerEpser(){
EPServiceProvider epServiceProvider =EPServiceProviderManager.getDefaultProvider();
String expression ="select avg(price) from org.wolf.esper.event.OrderEvent.win:time(30 sec)";
EPStatement epStatement =epServiceProvider.getEPAdministrator().createEPL(expression);
epStatement.addListener(new UpdateListener() {
public void update(EventBean[] arg0, EventBean[] arg1) {
System.out.println("==========="+arg0);
}
});
OrderEvent orderEvent = new OrderEvent();
orderEvent.setPrice(34.98f);
epServiceProvider.getEPRuntime().sendEvent(orderEvent);
}
public static void main(String[] args) {
handlerEpser();
}
}[/color]