Esper企业版介绍(四)Esper JDBC

本文介绍如何使用 Esper JDBC 构造模块在 Server 和 Client 端实现复杂事件处理(CEP)服务。Esper JDBC 使得 Esper 能够作为 JDBC 兼容的服务运行,允许客户端通过 SQL-92 查询来访问 Esper 的 Named Window 和 EPL Statements,从而实现对实时数据流的连续查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Server+Client构造模块

Server端JDBC实现:Esper JDBC(server行为)

Client端JDBC实现:Esper JDBC driver(单一jar包,~100kb)

Esper JDBC driver为 type 4 (full java)

Java Database Connectivity(JDBC)

定义的行业标准和接口(JAVA规范)

允许java和外部系统的互操作像数据库一样,也像CEP服务一样

客户端没有专门的锁定代码

Drivers以名字加载.

接口完全标准化.

Esper JDBC为JDBC3.0/JSR-54/SQL-92 compliant.

将Esper变成JDBC兼容的服务

通过Esper获得一个不断计算的随需而定的数据视图.

远程和本地的.

与现有的工具保持共通性:


Esper server必须在Esper JDBC server endpoint上启动

IP,Port(默认为8450),session idle timeout,threads.

JDBCEndpointConfiguration config = new JDBCEndpointConfiguration();
config.setListenPort(8450);
config.setSessionIdleTimeout(60); // 60-second idle timeout
JDBCEndpoint endpoint = new JDBCEndpoint(config);
endpoint.start();
Esper JDBC driver

JDBC Driver and URL or DataSource

Class.forName("com.espertech.esper.jdbc.remote.EPLRemoteJdbcDriver");
String url = "jdbc:esper:remote:127.0.01:8450"; // hostname:port
Connection connection = DriverManager.getConnection(url);
// or using Esper JDBC Data Source
EPLRemoteDataSource remoteDataSource = new EPLRemoteDataSource();
remoteDataSource.setServer("myhostname");
remoteDataSource.setPortNumber(8450);
Connection connection = remoteDataSource.getConnection();


Esper Named Window

一个持续流.

Esper JDBC 允许SQL-92查询 :select ... from [Named window] where ...

// Esper EPL (server side)
create window TickSummary.win:time(60 sec)
as select symbol, price from Tick
// JDBC (client side)
// import java.sql*;
String query = "select * from TickSummary where symbol = ‘GOOG’";
PreparedStatement stmt = connection.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
//... code to interrogate the result set
… rs.next();
… rs.getDouble(“price”);

Esper EPL Statement

在实时流内的持续查询.

Esper JDBC允许SQL-92存储过程call:  call [EPL Statement name]

// Esper EPL (server side)
select symbol, avg(price) as avp from Tick group by symbol
// assume statement name is avgPriceBySymbol
// JDBC (client side)
// import java.sql*;
String epl = "avgPriceBySymbol";
PreparedStatement stmt = connection.prepareStatement(epl);
ResultSet rs = stmt.executeQuery();
//... code to interrogate the result set
… rs.next();
… rs.getDouble(“avp”);



Example Named Windows

create window SearchRequests.win:time(1 min) as select * from SearchRequest

Example EPL Statements

select serviceName, count(*)
from SubmittedWorkEvent.win:time(60 sec) group by serviceName
output every 1 seconds
select serviceName, instanceId, avg(msecClockTime), count(*)
from CompletionEvent.win:time(60 sec) group by serviceName, instanceId
output every 1 seconds
select serviceName, avg(msecClockTime), count(*)
from CompletionEvent.win:time(60 sec) group by serviceName
output every 1 seconds
select queueName, avg(depth)
from QueueReportEvent.win:time(60 sec) group by queueName
output every 1 seconds



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王义凯_Rick

遇见即是缘,路过就给个评论吧~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值