JsonSerializationException при запуске Akka.net в режиме кластера с использованием API Akka.FSharp
Я пытаюсь реализовать кластер Akka.net с помощью API Akka.FSharp.
У меня есть следующий узел кластера, который служит семенем.
#r "nuget: Akka.FSharp"
#r "nuget: Akka.Cluster"
#r "nuget: Akka.TestKit"
open Akka
open Akka.FSharp
open Akka.Cluster
open System
open System.Configuration
let systemName = "script-cluster"
let nodeName = sprintf "cluster-node-%s" Environment.MachineName
let akkaConfig = Configuration.parse("""akka {
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
deployment {
/workerRouter = {
router = round-robin-pool
metrics-selector = cpu
nr-of-instances = 20
cluster {
enabled = on
use-role = worker
allow-local-routees = on
max-nr-of-instances-per-node = 5
}
}
}
}
remote {
log-remote-lifecycle-events = off
helios.tcp {
hostname = "127.0.0.1"
port = 2551
}
}
cluster {
min-nr-of-members = 1
roles = [master, worker]
role {
master.min-nr-of-members = 1
worker.min-nr-of-members = 1
}
seed-nodes = ["akka.tcp://script-cluster@127.0.0.1:2551"]
# when node cannot be reached within 10 sec, mark is as down
auto-down-unreachable-after = 10s
}
}""")
let actorSystem = akkaConfig |> System.create systemName
let cluster = Cluster.Get actorSystem
let demoActor (mailbox: Actor<_>) =
let rec loop() = actor {
printfn "Actor started %s" (mailbox.Self.Path.ToStringWithAddress())
let! message = mailbox.Receive()
return! loop ()
}
loop()
cluster.RegisterOnMemberUp (fun () ->
let workerRouter = spawnOpt actorSystem "workerRouter" demoActor [ Router(Akka.Routing.FromConfig.Instance) ]
printfn "Member is up, creating the router"
)
System.Console.ReadLine() |> ignore
И следующий узел, который пытается участвовать в кластере.
#r "nuget: Akka.FSharp"
#r "nuget: Akka.Cluster"
#r "nuget: Akka.TestKit"
open Akka
open Akka.FSharp
open Akka.Cluster
open System
open System.Configuration
let systemName = "script-cluster"
let nodeName = sprintf "cluster-node-%s" Environment.MachineName
let akkaConfig = Configuration.parse("""akka {
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
}
remote {
log-remote-lifecycle-events = off
helios.tcp {
hostname = "127.0.0.1"
port = 0
}
}
cluster {
roles = ["worker"] # custom node roles
seed-nodes = ["akka.tcp://script-cluster@127.0.0.1:2551"]
# when node cannot be reached within 10 sec, mark is as down
auto-down-unreachable-after = 10s
}
}""")
let actorSystem = akkaConfig |> System.create systemName
let demoActor (mailbox: Actor<_>) =
let rec loop() = actor {
printfn "Actor started %s" (mailbox.Self.Path.ToStringWithAddress())
let! message = mailbox.Receive()
return! loop ()
}
loop()
System.Console.ReadLine() |> ignore
Когда я пытаюсь запустить второй узел, я получаю это исключение.
[INFO][19-09-2021 14:23:03][Thread 0001][remoting (akka://script-cluster)] Starting remoting
[INFO][19-09-2021 14:23:03][Thread 0001][remoting (akka://script-cluster)] Remoting started; listening on addresses : [akka.tcp://script-cluster@127.0.0.1:53122]
[INFO][19-09-2021 14:23:03][Thread 0001][Cluster (akka://script-cluster)] Cluster Node [akka.tcp://script-cluster@127.0.0.1:53122] - Starting up...
[INFO][19-09-2021 14:23:03][Thread 0001][Cluster (akka://script-cluster)] Cluster Node [akka.tcp://script-cluster@127.0.0.1:53122] - Started up successfully
[INFO][19-09-2021 14:23:03][Thread 0044][Cluster (akka://script-cluster)] Cluster Node [akka.tcp://script-cluster@127.0.0.1:53122] - Welcome from [akka.tcp://script-cluster@127.0.0.1:2551]
[WARNING][19-09-2021 14:23:04][Thread 0030][akka.tcp://script-cluster@127.0.0.1:53122/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fscript-cluster%40127.0.0.1%3A2551-1] Association with remote system akka.tcp://script-cluster@127.0.0.1:2551 has failed; address is now gated for 5000 ms. Reason is: [Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON 'FSI_0002+workerRouter@62, FSI-ASSEMBLY'. Path '$type', line 1, position 59.
---> Newtonsoft.Json.JsonSerializationException: Could not find type 'FSI_0002+workerRouter@62' in assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(StructMultiKey`2 typeNameKey)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeByName(StructMultiKey`2 typeNameKey)
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.BindToType(String assemblyName, String typeName)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, String qualifiedTypeName)
Я новичок в F# и имею опыт работы на Java. Парадигма функционального программирования для меня довольно нова, поэтому приведенный выше код может не соответствовать обычным соглашениям F#. Любые предложения по улучшению кода приветствуются вместе с тем, как разрешить вышеуказанное исключение.