这可能是一个复制。
因此,我取得了一些进展。但是,我发现很难将来自C# API的参考文档解释为所需的Akka.FSharp API。
是否有使用"Akkling.Cluster.Sharding“在参与者之间发送消息的示例?
到目前为止,我只能从我的客户端程序发送消息,而不是演员。
let consumer (actor:Actor<_>) msg =
printfn "\n%A received %A" (actor.Self.Path.ToStringWithAddress()) (box msg) |> string |> ignored
let system1 = System.create "cluster-system" (configurePort 2551)
let shardRegion1 = spawnSharded id system1 "printer" <| props (actorOf2 consumer)
shardRegion1 <! ("shard-1", "entity-1", "hello world 1")上面的代码起作用。但是,它只使用字符串作为消息。我仍然在努力让演员们用各种类型的信息互相发送信息。
注:
我让Akka.Persistence.SqlServer插件正常工作了。
但是,我不清楚如何在后续设置中修改Akkling.Cluster.Sharding:
open Akka.FSharp
let clusterHostActor =
spawn system1 nodeName <| fun (inbox: Actor<_>) ->
let cluster = Cluster.Get system1
cluster.Subscribe(inbox.Self, [| typeof<ClusterEvent.IClusterDomainEvent> |])
inbox.Defer(fun () -> cluster.Unsubscribe(inbox.Self))
let rec messageLoop () =
actor {
let! message = inbox.Receive()
match box message with
| :? ClusterEvent.MemberUp as event -> printfn "Member %s Joined the Cluster at %O" event.Member.Address.Host DateTime.Now
let sref = select (event.Member.Address.ToString() + "/user/listener") inbox
sref <! "Hello from clusterHostActor"
| :? ClusterEvent.MemberRemoved as event -> printfn "Member %s Left the Cluster at %O" event.Member.Address.Host DateTime.Now
| other -> printfn "Cluster Received event %O at %O" other DateTime.Now
return! messageLoop()
}
messageLoop()具体来说,我的印象是,为了在参与者之间来回发送消息,在切分集群系统中需要一个碎片区域。
作为这个范例的新手,我正努力在两个参与者之间创建一个简单的"hello world“类型的消息传递程序,使用分片功能。
有什么建议吗?
发布于 2017-03-17 12:31:26
如果希望碎片节点成为切分参与者的有效主机/容器,则必须运行与该类型的参与者关联的碎片区域。发送给共享参与者的所有消息都通过shardRegion引用发送。
在第一个示例片段中,您已经表明,字符串消息是唯一有效的消息类型,这可能是因为您的consumer 行为将字符串作为唯一有效的消息类型。
正如您在spawnSharded 定义中所看到的,它需要4个参数。这里重要的是第一个,它是一个函数,用于解析切分插件所需的所有信息,以便将消息路由到有效的参与者/实体。此方法返回一个元组,其中:
因为在这个例子中,这个消息解析器函数是id (identity),所以我们直接向shard区域发送一个元组。您可以将该函数更改为任何您想要指定的自定义内容。
PS:如果你有更多的问题,Akka.NET https://gitter.im/akkadotnet/akka.net是你可以找到帮助的地方。
https://stackoverflow.com/questions/42840603
复制相似问题