2

我使用了配置为 sql server 插件的持久性actor。下面是我的 hocon 配置。

这里数据源连接字符串设置为我的本地主机。

是否可以在演员系统初始化之前从 C# 代码中设置此连接字符串?

akka.persistence {
          journal {
            plugin = "akka.persistence.journal.sql-server"                
            sql-server {
                  class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
                  plugin-dispatcher = "akka.actor.default-dispatcher"

                  # connection string used for database access
                  connection-string = "Data Source=ES-NB-046\\MSSQLSERVER_2014;Initial Catalog=SwedolTest;User ID=sa;Password=aaaaaa@;"
                  # can alternativly specify: connection-string-name

                  # default SQL timeout
                  connection-timeout = 30s

                  # SQL server schema name
                  schema-name = dbo

                  # persistent journal table name
                  table-name = EventJournal

                  # initialize journal table automatically
                  auto-initialize = on

                  timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
                  metadata-table-name = Metadata
            }
          } 

          snapshot-store {
            plugin = "akka.persistence.snapshot-store.sql-server"
              sql-server {
                class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
                plugin-dispatcher = "akka.actor.default-dispatcher"
                table-name = SnapshotStore
                schema-name = dbo
                auto-initialize = on
                connection-string = "Data Source=ES-NB-046\\MSSQLSERVER_2014;Initial Catalog=SwedolTest;User ID=sa;Password=aaaaaa@;"
             }
          }

      }
4

1 回答 1

0

您可以使用配置后备

namespace AkkaTest
{
    using Akka.Actor;
    using Akka.Configuration;

    class Program
    {
        static void Main(string[] args)
        {
            //Main config could be load different ways. This is placeholder
            var mainConfig = ConfigurationFactory.Default();
            var conString = GetConnectionString();

            var conStringConfig = ConfigurationFactory.ParseString(
                $@"akka.persistence.journal.sqlite.connection-string        = ""{conString}""
                   akka.persistence.snapshot-store.sqlite.connection-string = ""{conString}""
            ");

            mainConfig = mainConfig.WithFallback(conStringConfig);

            var system = ActorSystem.Create("stackOverflow", mainConfig);
        }

        private static string GetConnectionString()
        {
            return "1";
        }
    }
}
于 2017-03-21T15:52:03.343 回答