Esper:如何使用Esper的配置API通过JDBC配置Esper以连接关系数据库 [英] Esper: How to configure Esper to connect a Relational Database, through a JDBC, using Esper's configuration API

查看:64
本文介绍了Esper:如何使用Esper的配置API通过JDBC配置Esper以连接关系数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用Esper引擎(v5.0.0)的Java客户端应用程序如何配置引擎实例,以便他可以连接到关系数据库,例如pgSQL.

I would like to know how a java client application that is using Esper's engine (v5.0.0) may configure engine instance so he can to connect to a relation database, say pgSQL.

这对于编写能够将事件流(或数据流)与数据库中的静态/历史数据结合起来的EPL查询至关重要( EsperIO适配器.)

This is essential to write EPL queries capable to join event streams (or data stream) with static/historic data from a database (5.13. Accessing Relational Data via SQL). That is, to Read from a database. (Write to a database requires the usage of a EsperIO adapter.)

来自 Esper的文档我发现

From Esper's docs I figure out that Configuration and ConfigurationDBRef classes should be used to configure Esper's database connection through its API.

但是,根据我的最佳研究,其余文档对于整个配置过程不是很清楚,而我正为此努力奋斗.

However, at the best of my research, the remaining documentation is not very clear about the entire configuration process, for which I'm struggling to.

推荐答案

以下代码段显示了整个配置过程:

The following code snippet shows the entire configuration process:

ConfigurationDBRef dbConfig = new ConfigurationDBRef();
dbConfig.setDriverManagerConnection("org.postgresql.Driver",
                                    "jdbc:postgresql://localhost:5432/database_name", 
                                    "user", 
                                    "password");

Configuration engineConfig = new Configuration();
engineConfig.addDatabaseReference("database_alias", dbConfig);

esperEngine = EPServiceProviderManager.getDefaultProvider(engineConfig);

就是这样. esperEngine 将成为您的引擎实例,准备与 database_name 进行通信,并以 database_alias 作为查询statemet别名(用于查询的 FROM 子句)

And that's it. esperEngine will be your engine instance prepared to communicate with database_name with database_alias as the query statemet alias (used in the query's FROM clause)

您可以通过以下方式在Esper的实例中安装查询:

You can install a query in Esper's instance in the following manner:

String statement =  "SELECT datastream.column1,  rel.column2"                           + 
                    "FROM   Datastream.Measure AS datastream, "                         +
                           "sql:database_alias ['SELECT column2 "                       +
                                                "FROM \"SchemaX\".\"TableY\" ] AS rel";

//Install this query in the engine
EPStatement queryEngineObject = esperEngine.getEPAdministrator().createEPL(statement);  

//Associate a Listener to this query
MyQueryListener listener = new MyQueryListener(); //that implements UpdateListener Interface
queryEngineObject.addListener(listener);

这篇关于Esper:如何使用Esper的配置API通过JDBC配置Esper以连接关系数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆