Skip to content

Instantly share code, notes, and snippets.

@codingedgar
Last active September 21, 2020 20:02
Show Gist options
  • Select an option

  • Save codingedgar/2651bf308a03558d0fe2ffcd5870f34b to your computer and use it in GitHub Desktop.

Select an option

Save codingedgar/2651bf308a03558d0fe2ffcd5870f34b to your computer and use it in GitHub Desktop.
f# akka.net akkling minimal cluster sharding config
#load ".paket/load/netstandard2.0/Akka.Serialization.Hyperion.fsx"
#load ".paket/load/netstandard2.0/Akka.Cluster.Sharding.fsx"
#r "packages/Akkling/lib/netstandard2.0/Akkling.dll"
#r "packages/Akkling.Persistence/lib/netstandard2.0/Akkling.Persistence.dll"
#r "packages/Akkling.Cluster.Sharding/lib/netstandard2.0/Akkling.Cluster.Sharding.dll"
open System
open System.Threading
open Akkling
open Akkling.Cluster.Sharding
type Command = | Path
let buildMatchUp =
props (fun context ->
let rec start () =
actor {
let! command = context.Receive()
match command with
| Path ->
context.Sender()
<! context.Self.Path.ToStringWithAddress()
return! start ()
}
printfn "started"
start ())
let config =
Configuration.parse
("""
akka {
loglevel = "OFF"
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
}
remote {
helios.tcp {
public-hostname = "localhost"
hostname = "localhost"
port = 5000
}
}
cluster {
seed-nodes = [ "akka.tcp://TicTacToe@localhost:5000/" ]
}
}
""")
|> fun config -> config.WithFallback(Configuration.defaultConfig ())
let system = System.create "TicTacToe" config
let region =
entityFactoryFor system "match_up" buildMatchUp
printfn "No entity is created yet"
Thread.Sleep(1000)
let entity = region.RefFor "shard-1" "entity-1"
printfn "Entity isn't created here either"
Thread.Sleep(1000)
entity
<? Path
|> Async.RunSynchronously
|> printfn "Path: %A"
// No entity is created yet
// Entity isn't created here either
// started
// Path: "akka://TicTacToe/system/sharding/match_up/shard-1/entity-1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment