esper简单入门之demo

采用maven项目管理模式
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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值