0

我正在尝试将 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"));
            }
        }
4

1 回答 1

0

下面是解析驱动程序类型的代码,即 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 + "'");
}
于 2021-09-15T05:20:11.733 回答