gpt4 book ai didi

c# - 如何从后面的 C# 代码为 akka.net 持久性 actor 设置连接字符串

转载 作者:太空宇宙 更新时间:2023-11-03 15:07:03 25 4
gpt4 key购买 nike

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

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

是否可以在 actor 系统初始化之前从后面的 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@;"
}
}

}

最佳答案

你可以使用 Configuration Fallbacks :

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";
}
}
}

关于c# - 如何从后面的 C# 代码为 akka.net 持久性 actor 设置连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42929543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com