下面的代碼片段顯示了整個配置過程:
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_alias作爲查詢statemet別名與數據庫名稱溝通你的引擎實例(用於查詢的FROM子句)
您可以通過以下方式安裝在艾斯波的情況下查詢:
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);
嗨,我有同樣的問題。我跟着你的同一步驟。但問題是我的聽衆沒有收到任何數據庫中的數據。 – Sajithv 2015-04-10 09:06:27
和配置似乎工作正常,但沒有結果。 – Sajithv 2015-04-10 09:07:07