【问题标题】:Esper: How to configure Esper to connect a Relational Database, through a JDBC, using Esper's configuration APIEsper:如何使用 Esper 的配置 API 通过 JDBC 配置 Esper 以连接关系数据库
【发布时间】:2014-11-04 12:22:14
【问题描述】:

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

这对于编写能够将事件流(或数据流)与来自数据库 (5.13. Accessing Relational Data via SQL) 的静态/历史数据连接起来的 EPL 查询至关重要。也就是说,从数据库中读取。 (写入数据库需要使用EsperIO adapter。)

Esper's docs 我发现ConfigurationConfigurationDBRef 类应该用于通过其API 配置Esper 的数据库连接。

但是,在我的研究中,剩下的文档对整个配置过程并不是很清楚,我正在为此努力。

【问题讨论】:

    标签: java database jdbc configuration esper


    【解决方案1】:

    下面的代码sn -p展示了整个配置过程:

    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 作为查询语句别名(用于查询的 FROM强>子句)

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

    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);
    

    【讨论】:

    • 您好,我也有同样的问题。我的步骤与您的相同。但问题是我的听众没有从数据库中接收到任何数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多