使用SQL Server作为Orleans存储

Zel*_*tor 5 sql-server provider orleans

我正在尝试将SQL Server用作Orleans的数据存储.

我已设法使用Azure本地存储模拟器使我的解决方案正常工作,但无法使其与SQL Server的本地实例一起使用.我使用以下方法创建了数据库:

https://github.com/dotnet/orleans/blob/master/src/OrleansSQLUtils/CreateOrleansTables_SqlServer.sql

并使我的配置文件看起来像这里的那个:

http://dotnet.github.io/orleans/Documentation/Advanced-Concepts/Configuring-SQL-Tables.html

这是我的配置文件:

<?xml version="1.0" encoding="utf-8"?>
<OrleansConfiguration xmlns="urn:orleans">
  <Globals>
    <StorageProviders>
      <SystemStore SystemStoreType ="SqlServer"
           DeploymentId="OrleansTest"
           DataConnectionString="Data Source=.\SQL2014;Initial Catalog=Orleans;Integrated Security=True;Pooling=False;Max Pool Size=200;Asynchronous Processing=True;MultipleActiveResultSets=True" AdoInvariant="System.Data.SqlClient" />
      <Provider Type="Orleans.SqlUtils.StorageProvider.SqlStorageProvider" Name="SqlServer" />
      <!--<Provider Type="Orleans.Storage.AzureTableStorage" Name="AzureStore" DataConnectionString="UseDevelopmentStorage=true" />-->
    </StorageProviders>
    <SeedNode Address="localhost" Port="11111" />
  </Globals>
  <Defaults>
    <Networking Address="localhost" Port="11111" />
    <ProxyingGateway Address="localhost" Port="30000" />
  </Defaults>
</OrleansConfiguration>
Run Code Online (Sandbox Code Playgroud)

我在谷物中添加了以下属性:

[StorageProvider(ProviderName = "SqlServer")]
Run Code Online (Sandbox Code Playgroud)

然后我得到以下错误: Could not locate a state map factory type...

请有人让我知道我需要添加到提供商或我是否做了其他错误的事情?我是否需要为SQL提供程序创建与StateMapFactoryType有关的内容?

谢谢

Boz*_*Joe 4

首先,这<SystemStore>不是 StorageProvider。该节点用于成员资格预言机。像这样:

<OrleansConfiguration xmlns="urn:orleans">
  <Globals>
    <SystemStore SystemStoreType ="SqlServer"
       DeploymentId="OrleansTest"
       DataConnectionString="Data Source=.\SQL2014;Initial Catalog=Orleans;Integrated Security=True;Pooling=False;Max Pool Size=200;Asynchronous Processing=True;MultipleActiveResultSets=True" AdoInvariant="System.Data.SqlClient" />        
  </Globals>
  <Defaults>
    <Networking Address="" Port="11111" />
    <ProxyingGateway Address="" Port="30000" />
  </Defaults>
</OrleansConfiguration>
Run Code Online (Sandbox Code Playgroud)

现在让我们输入您的 StorageProvider

<OrleansConfiguration xmlns="urn:orleans">
  <Globals>

<StorageProviders>
  <Provider Type="Orleans.SqlUtils.StorageProvider.SqlStorageProvider" Name="SqlServer" />
</StorageProviders>


    <SystemStore SystemStoreType ="SqlServer"
       DeploymentId="OrleansTest"
       DataConnectionString="Data Source=.\SQL2014;Initial Catalog=Orleans;Integrated Security=True;Pooling=False;Max Pool Size=200;Asynchronous Processing=True;MultipleActiveResultSets=True" AdoInvariant="System.Data.SqlClient" />        
  </Globals>
  <Defaults>
    <Networking Address="" Port="11111" />
    <ProxyingGateway Address="" Port="30000" />
  </Defaults>
</OrleansConfiguration>
Run Code Online (Sandbox Code Playgroud)

现在到有趣的部分了。设置Orleans.SqlUtils.StorageProvider.SqlStorageProvider

这个特定的存储提供程序基于 P&P 集团的 ElasticClient,它使用特殊的分片数据库(例如分片主数据库和分片数据库)

可能会建议这个较低摩擦的提供程序(插入无耻的插件(如果它有效,我写了它,如果它不起作用,那么我不知道是谁做的:D)https://github.com/OrleansContrib/Orleans.StorageProviders.SimpleSQLServerStorage

ok,回到Orleans.SqlUtils.StorageProvider.SqlStorageProvider 你还需要几个配置项:

  • 连接字符串
  • 地图名称
  • StateMapFactory类型

<Provider Type="Orleans.SqlUtils.StorageProvider.SqlStorageProvider" Name="guts"  ConnectionString = "Server=.;Initial catalog=guts;Integrated Security=SSPI;" MapName="guts" StateMapFactoryType="ClassName, assemblyname" />
Run Code Online (Sandbox Code Playgroud)

您需要创建 StateMapFactory 实现,Orleans.SqlUtils.StorageProvider.IGrainStateMapFactory 请参阅 https://github.com/dotnet/orleans/blob/v1.1.3/src/OrleansSQLUtils/Storage/Provider/IGrainStateMapFactory.cs

您可以使用https://github.com/dotnet/orleans/blob/v1.1.3/src/TesterInternal/StorageTests/SQLAdapter/SampleGrainStateMapFactory.cs 作为参考

但!!看起来版本 1.1.3 仍然标记Orleans.SqlUtils.StorageProvider.IGrainStateMapFactory为内部,因此您必须从源代码编译或从 github 获取最新版本。