2017-08-29 81 views
1

(1)我需要將Esper數據庫適配器連接到我的項目。使用this 爲指導IM,但我不知道在哪裏可以找到的配置文件,因爲即時得到這個錯誤:Cannot locate configuration information for database 'db1'將Esper與PostgreSQL連接

這是我

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是什麼。

+0

也許你不得不使用'sql:db_name'來代替'sql:db1'? –

+0

@YCF_L nop,我已經試過了 –

回答

0

而不是「EPServiceProviderManager.getDefaultProvider();」你會想使用「EPServiceProviderManager.getDefaultProvider(configuration);」。

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