This may be a duplicate.
Thus, I have made some progress. However, I find it challenging to interpret the reference documentation from the C# API to the desired Akka.FSharp API.
Is there an example of sending messages between actors using "Akkling.Cluster.Sharding"?
As of now, I am only able to send messages from my client program and not an actor.
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")
The code above works. However, it only works with strings as messages. I am still struggling to get actors to send messages to each other with various typed messages.
NOTE:
I got the Akka.Persistence.SqlServer plugin working.
However, I am not clear on how to retrofit the following setup within 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()
Specifically, I was under the impression that a shard-region is required within a sharded cluster system in order to send messages back and forth between actors.
As someone that is new to this paradigm, I am struggling to create a simple "hello world" type messaging program between two actors using the sharding functionality.
Any suggestions?