(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是什么。

最佳答案

您需要使用“EPServiceProviderManager.getDefaultProvider(配置)”,而不是“EPServiceProviderManager.getDefaultProvider();”。

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

关于java - 将Esper与PostgreSQL连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45939845/

10-10 20:16