System.Format 使用 Akka.Persistence 配置时出现异常
System.Format exception when consuming Akka.Persistence configuration
我正在努力解决因解析我的 Akka.Net 配置文件而导致的 System.Format 异常。
我知道异常源于配置的持久化块:
persistence{
journal {
plugin = "akka.persistence.journal.sql-server"
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = "akka.actor.default-dispatcher"
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = EventJournal
# should corresponding journal table be initialized automatically
auto-initialize = off
# timestamp provider used for generation of journal entries timestamps
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
# metadata table
metadata-table-name = Metadata
}
}
snapshot-store {
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = ""akka.actor.default-dispatcher""
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = SnapshotStore
# should corresponding journal table be initialized automatically
auto-initialize = off
}
}
}
反映异常的输出如下:
Binding session to 'C:\Users\Snimrod\Desktop\Akkling-master\examples\../src/Akkling.Cluster.Sharding/bin/Debug/Akka.dll'...
System.FormatException: Unknown escape code: S
at Akka.Configuration.Hocon.HoconTokenizer.PullEscapeSequence()
at Akka.Configuration.Hocon.HoconTokenizer.PullQuotedText()
at Akka.Configuration.Hocon.HoconTokenizer.PullValue()
at Akka.Configuration.Hocon.Parser.ParseValue(HoconValue owner, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
> at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseText(String text, Func`2 includeCallback)
at Akka.Configuration.ConfigurationFactory.ParseString(String hocon)
at Akkling.Configuration.parse(String arg00) in C:\Users\Snimrod\Desktop\Akkling-master\src\Akkling\Spawning.fs:line 30
at FSI_0003.configWithPort[a](a port) in C:\Users\Snimrod\Desktop\Akkling-master\examples\cluster-sharding.fsx:line 148
at <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\Users\Snimrod\Desktop\Akkling-master\examples\cluster-sharding.fsx:line 154
Stopped due to error
我的整个配置如下:
let configWithPort port =
let config = Configuration.parse ("""
akka {
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
serializers {
hyperion = "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
}
serialization-bindings {
"System.Object" = hyperion
}
}
remote {
helios.tcp {
public-hostname = "localhost"
hostname = "localhost"
port = """ + port.ToString() + """
}
}
cluster {
auto-down-unreachable-after = 5s
seed-nodes = [ "akka.tcp://cluster-system@localhost:2551/" ]
}
# persistence {
# journal.plugin = "akka.persistence.journal.inmem"
# snapshot-store.plugin = "akka.persistence.snapshot-store.local"
# }
persistence{
journal {
plugin = "akka.persistence.journal.sql-server"
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = "akka.actor.default-dispatcher"
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = EventJournal
# should corresponding journal table be initialized automatically
auto-initialize = off
# timestamp provider used for generation of journal entries timestamps
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
# metadata table
metadata-table-name = Metadata
}
}
snapshot-store {
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = ""akka.actor.default-dispatcher""
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = SnapshotStore
# should corresponding journal table be initialized automatically
auto-initialize = off
}
}
}
}
""")
config.WithFallback(ClusterSingletonManager.DefaultConfig())
以下行导致我描述的异常:
let system1 = System.create "cluster-system" (configWithPort 2551)
总而言之,我是 Akka.Net 的新手,正在努力解决发生此异常的原因。
看起来 HOCON 解析器可能对 \
有问题并将其视为转义字符。将其更改为 \
应该可以解决问题。
我正在努力解决因解析我的 Akka.Net 配置文件而导致的 System.Format 异常。
我知道异常源于配置的持久化块:
persistence{
journal {
plugin = "akka.persistence.journal.sql-server"
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = "akka.actor.default-dispatcher"
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = EventJournal
# should corresponding journal table be initialized automatically
auto-initialize = off
# timestamp provider used for generation of journal entries timestamps
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
# metadata table
metadata-table-name = Metadata
}
}
snapshot-store {
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = ""akka.actor.default-dispatcher""
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = SnapshotStore
# should corresponding journal table be initialized automatically
auto-initialize = off
}
}
}
反映异常的输出如下:
Binding session to 'C:\Users\Snimrod\Desktop\Akkling-master\examples\../src/Akkling.Cluster.Sharding/bin/Debug/Akka.dll'...
System.FormatException: Unknown escape code: S
at Akka.Configuration.Hocon.HoconTokenizer.PullEscapeSequence()
at Akka.Configuration.Hocon.HoconTokenizer.PullQuotedText()
at Akka.Configuration.Hocon.HoconTokenizer.PullValue()
at Akka.Configuration.Hocon.Parser.ParseValue(HoconValue owner, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
> at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseKeyContent(HoconValue value, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseObject(HoconValue owner, Boolean root, String currentPath)
at Akka.Configuration.Hocon.Parser.ParseText(String text, Func`2 includeCallback)
at Akka.Configuration.ConfigurationFactory.ParseString(String hocon)
at Akkling.Configuration.parse(String arg00) in C:\Users\Snimrod\Desktop\Akkling-master\src\Akkling\Spawning.fs:line 30
at FSI_0003.configWithPort[a](a port) in C:\Users\Snimrod\Desktop\Akkling-master\examples\cluster-sharding.fsx:line 148
at <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\Users\Snimrod\Desktop\Akkling-master\examples\cluster-sharding.fsx:line 154
Stopped due to error
我的整个配置如下:
let configWithPort port =
let config = Configuration.parse ("""
akka {
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
serializers {
hyperion = "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
}
serialization-bindings {
"System.Object" = hyperion
}
}
remote {
helios.tcp {
public-hostname = "localhost"
hostname = "localhost"
port = """ + port.ToString() + """
}
}
cluster {
auto-down-unreachable-after = 5s
seed-nodes = [ "akka.tcp://cluster-system@localhost:2551/" ]
}
# persistence {
# journal.plugin = "akka.persistence.journal.inmem"
# snapshot-store.plugin = "akka.persistence.snapshot-store.local"
# }
persistence{
journal {
plugin = "akka.persistence.journal.sql-server"
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = "akka.actor.default-dispatcher"
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = EventJournal
# should corresponding journal table be initialized automatically
auto-initialize = off
# timestamp provider used for generation of journal entries timestamps
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
# metadata table
metadata-table-name = Metadata
}
}
snapshot-store {
sql-server {
# qualified type name of the SQL Server persistence journal actor
class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
# dispatcher used to drive journal actor
plugin-dispatcher = ""akka.actor.default-dispatcher""
# connection string used for database access
connection-string = "Data Source=MyMachineName\SQLEXPRESS;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
# default SQL commands timeout
connection-timeout = 30s
# SQL server schema name to table corresponding with persistent journal
schema-name = dbo
# SQL server table corresponding with persistent journal
table-name = SnapshotStore
# should corresponding journal table be initialized automatically
auto-initialize = off
}
}
}
}
""")
config.WithFallback(ClusterSingletonManager.DefaultConfig())
以下行导致我描述的异常:
let system1 = System.create "cluster-system" (configWithPort 2551)
总而言之,我是 Akka.Net 的新手,正在努力解决发生此异常的原因。
看起来 HOCON 解析器可能对 \
有问题并将其视为转义字符。将其更改为 \
应该可以解决问题。