我正在尝试将 Nesper 连接到外部数据库(最初是 sqlite),但无法解析该类型。我在配置例程“com.espertech.esper.client.EPException:'无法解析驱动程序'PgSQL''的类型”中遇到异常似乎也影响PgSQL。关于缺少什么的任何帮助?
esper.xml 配置
<esper-configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.espertech.com/schema/esper">
<database-reference name="db2">
<driver type="PgSQL" connection-string="Host=nesper-pgsql-integ.local;Database=test;Username=esper;Password=3sp3rP@ssw0rd;"/>
<connection-settings auto-commit="false" catalog="test" read-only="true" transaction-isolation="ReadCommitted"/>
<connection-lifecycle value="retain"/>
<lru-cache size="1000"/>
<column-change-case value="uppercase"/>
<metadata-origin value="metadata"/>
</database-reference>
</esper-configuration>
初始化例程在 config.Configure(url) 处引发异常
static void InitializeEsper()
{
string url = @".\esper.xml";
Configuration config = new Configuration();
config.Configure(url); // Fails here
var serviceProvider = EPServiceProviderManager.GetDefaultProvider(config);
_runtime = serviceProvider.EPRuntime;
_administrator = serviceProvider.EPAdministrator;
_administrator.Configuration.AddEventType<TradeEvent>();
_administrator.Configuration.AddEventType<SampleEvent>();
_administrator.Configuration.AddEventType<QueryEvent>();
}
异常消息是:“无法解析驱动程序 'PgSQL' 的类型”
堆栈跟踪是:
" 在 com.espertech.esper.client.DbDriverFactoryConnection.ResolveDriverTypeFromName(String driverName)\r\n at com.espertech.esper.client.ConfigurationDBRef.SetDatabaseDriver(IContainer container, String driverName, Properties properties)\r\n at com. espertech.esper.client.ConfigurationParser.HandleDatabaseRefs(配置配置,XmlElement 元素)\r\n 在 com.espertech.esper.client.ConfigurationParser.DoConfigure(配置配置,XmlElement rootElement)\r\n 在 com.espertech.esper。 client.ConfigurationParser.DoConfigure(Configuration configuration, Stream stream, String resourceName)\r\n at com.espertech.esper.client.Configuration.Configure(String resource)\r\n at SlidingWindow.Program.InitializeEsper() in C: \Users\esas\source\repos\esas\Nesper-Practice\SlidingWindow\Program.cs:第 116 行\r\n 在 SlidingWindow。Program.Main(String[] args) 在 C:\Users\esas\source\repos\esas\Nesper-Practice\SlidingWindow\Program.cs:line 33"
我能够在代码中添加一个数据库(完全独立的项目)
static void InitializeAndRun()
{
var container = ContainerExtensions.CreateDefaultContainer(false);
container.RegisterDatabaseDriver(typeof(DbDriverSQLite)).InitializeDefaultServices().InitializeDatabaseDrivers();
Configuration config = new Configuration(container);
//Add database
ConfigurationCommonDBRef dbref = new ConfigurationCommonDBRef();
dbref.SetDatabaseDriver("DbDriverSQLite", "Data Source=.\\Db\\esperapp.db", new Properties());
config.Common.AddDatabaseReference("esperdb", dbref);
Console.WriteLine("Found Databases {0}", config.Common.DatabaseReferences.Count.ToString());
_runtime = EPRuntimeProvider.GetDefaultRuntime(config);
var statementText = "select * from " +
"sql:esperdb [\"SELECT Timestamp,Source,Status FROM Events\"] output all";
var statement = _runtime.DeployStatement(statementText);
//Print Table contents
var enumerator = statement.GetEnumerator();
while (enumerator.MoveNext())
{
var e = enumerator.Current;
Console.WriteLine("{0}, {1}, {2} ", e.Get("Timestamp"), e.Get("Source"), e.Get("Status"));
}
}