将Esper与PostgreSQL连接

时间:2017-08-29 12:58:57

标签: java postgresql esper

(1)我需要将Esper数据库适配器连接到我的项目。我正在使用this 作为指南,但我不知道在哪里找到配置文件,因为我收到此错误:Cannot locate configuration information for database 'db1'

这就是我所拥有的

public class Esper {


public void iniciar() {
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();

    ConfigurationDBAdapter adapterConfig = new ConfigurationDBAdapter();
    ConfigurationDBRef configDB = new ConfigurationDBRef();
    configDB.setDriverManagerConnection("org.postgresql.Driver",
            "jdbc:postgresql://localhost:5432/db_name", 
            "user", 
            "pass");
    adapterConfig.getJdbcConnections().put("db1", configDB);

    EsperIODBAdapter dbAdapter = new EsperIODBAdapter(adapterConfig, "engineURI");
    dbAdapter.start();

    String expression = "select * from pattern[every timer :interval(10)], sql:db1 ['select mosquitoId from registros where velocidad > 50']";
    EPStatement stmt = epService.getEPAdministrator().createEPL(expression);
    Mylistener listener = new Mylistener();
    stmt.addListener(listener);
}
}

(2)我需要做的是从表Registros获取数据,如果velocidad > 50使用printLn(),我不明白示例中的pattern是什么。

1 个答案:

答案 0 :(得分:1)

取代" EPServiceProviderManager.getDefaultProvider();"你想要使用" EPServiceProviderManager.getDefaultProvider(配置);"。

Configuration configuration = new Configuration();
ConfigurationDBRef configDB = new ConfigurationDBRef();
configDB.setDriverManagerConnection(....);
configuration.addDatabaseReference("MyDB", configDB);
EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);