Skip to content

Instantly share code, notes, and snippets.

@rdavisau
Created Aug 10, 2015
Embed
What would you like to do?
Akka.Cluster + Discriminated Union test
open System
open System.IO
open System.Net
open Akka
open Akka.Actor
open Akka.FSharp
open Akka.Remote
open Akka.Actor
open Akka.Cluster
type Message =
| Marco
| LogLocal of string
| Echo of string
let publicHostname = "localhost" //(new WebClient()).DownloadString(@"https://api.ipify.org")
let makeHost() =
let init () =
let initSystem name port =
let configData =
"""
akka {
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
}
remote {
log-remote-lifecycle-events = DEBUG
log-received-messages = on
helios.tcp {
port = {1}
hostname = 0.0.0.0
public-hostname = {0}
maximum-frame-size = 4000000b
}
}
cluster {
seed-nodes = ["akka.tcp://{2}@{0}:{1}"]
}
}
"""
.Replace("{0}", publicHostname)
.Replace("{1}", port.ToString())
.Replace("{2}", name)
let config = Configuration.parse configData
System.create name config
initSystem "cluster" 54050
init()
let makeNodes () =
let initialise port =
let publicHostname = "localhost" // (new WebClient()).DownloadString(@"https://api.ipify.org")
let initSystem systemname localport seedhost seedport =
let configData =
"""
akka {
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
}
remote {
log-remote-lifecycle-events = DEBUG
log-received-messages = on
helios.tcp {
port = {1}
hostname = 0.0.0.0
public-hostname = {0}
maximum-frame-size = 4000000b
}
}
cluster {
seed-nodes = ["akka.tcp://{2}@{3}:{4}"]
}
}
""" // only god can judge me for this
.Replace("{0}", publicHostname) // .. ..
.Replace("{1}", localport.ToString()) // "" ""
.Replace("{2}", systemname) // ++
.Replace("{3}", seedhost) // \\ //
.Replace("{4}", seedport.ToString()) // -------
let config = Configuration.parse configData
System.create systemname config
let system = initSystem "cluster" port publicHostname 54050
printfn "Ready to get my deployed-to on"
spawn system "simpleton" (actorOf (fun msg -> printfn "%A" msg))
[54051..54059] |> List.map initialise
let host = makeHost()
let nodes = makeNodes()
// no problems here.
let worksGood () = (select "akka.tcp://cluster@localhost:54054/user/simpleton" host) <! "s"
// some problems here.
let worksBad () = (select "akka.tcp://cluster@localhost:54054/user/simpleton" host) <! LogLocal("s")
// worksGood()
// worksBad()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment