我试图将Nesper连接到一个外部数据库(最初是sqlite),但没有任何东西能够解析该类型。我在配置例程"com.espertech.esper.client.EPException:'Unable to resolve type for driver ' 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 configuration)\r\n在com.espertech.esper.client.ConfigurationDBRef.SetDatabaseDriver(IContainer container,String driverName,Properties driverName)\r\n在com.espertech.esper.client.ConfigurationParser.DoConfigure(Configuration configuration,XmlElement driverName)\r\n在com.espertech.esper.client.ConfigurationParser.DoConfigure(Configuration configuration,XmlElement rootElement)\r\n在com.espertech.esper.client.ConfigurationParser.DoConfigure(Configuration configuration,stream rootElement,字符串resourceName)\r\n位于com.espertech.esper.client.Configuration.Configure(String资源)\r\n位于C:\Users\esas\source\repos\esas\Nesper-Practice\SlidingWindow\Program.cs:line 116中的SlidingWindow.Program.InitializeEsper() \r\n位于C:\Users\esas\source\repos\esas\Nesper-Practice\SlidingWindow\Program.cs:line 33中的SlidingWindow.Program.Main(String[]参数)“
我能够在代码中添加一个数据库(完全独立的项目)
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"));
}
}发布于 2021-09-15 05:20:12
下面是解析驱动程序类型的代码,即DbDriverConnectionHelper的方法ResolveDriverTypeFromName。它会尝试按照以下步骤解析该名称。
/// <summary>
/// Resolves the driver type from the name provided. If the driver can not be
/// resolved, the method throws an exception to indicate that one could not
/// be found. The method first looks for a class that matches the name of
/// the driver. If one can not be found, it checks in the com.espertech.esper.epl.drivers
/// namespace to see if one can be found. Lastly, if checks in the
/// com.espertech.espers.eql.drivers namespace with a variation of the given driver name.
/// </summary>
/// <param name="driverName">Name of the driver.</param>
/// <returns></returns>
public static Type ResolveDriverTypeFromName(string driverName)
{
Type driverType;
// Check for the type with no modifications
if ((driverType = TypeHelper.ResolveType(driverName, false)) != null) {
return driverType;
}
// Check for the type in the driverNamespace
string specificName = $"{DriverNamespace}.{driverName}";
if ((driverType = TypeHelper.ResolveType(specificName, false)) != null) {
return driverType;
}
// Check for the type in the driverNamespace, but modified to include
// a prefix to the name.
string pseudoName = $"{DriverNamespace}.DbDriver{driverName}";
if ((driverType = TypeHelper.ResolveType(pseudoName, false)) != null) {
return driverType;
}
// Driver was not found, throw an exception
throw new EPException("Unable to resolve type for driver '" + driverName + "'");
}https://stackoverflow.com/questions/69168988
复制相似问题