Created
August 20, 2015 12:23
-
-
Save Horusiath/5423cd5e03b8ef82b227 to your computer and use it in GitHub Desktop.
Akka.Fsharp remote deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Akka.FSharp | |
open Akka.Actor | |
// return Deploy instance able to operate in remote scope | |
let deployRemotely address = Deploy(RemoteScope (Address.Parse address)) | |
let spawnRemote systemOrContext remoteSystemAddress actorName expr = | |
spawne systemOrContext actorName expr [SpawnOption.Deploy (deployRemotely remoteSystemAddress)] | |
let config = | |
Configuration.parse | |
@"akka { | |
actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" | |
remote.helios.tcp { | |
hostname = localhost | |
port = 0 | |
} | |
}" | |
[<EntryPoint>] | |
let main argv = | |
let system = System.create "local-system" config | |
let aref = | |
spawnRemote system "akka.tcp://remote-system@localhost:9001/" "hello" | |
// actorOf wraps custom handling function with message receiver logic | |
<@ actorOf (fun msg -> printfn "received '%s'" msg) @> | |
// send example message to remotely deployed actor | |
aref <! "Hello world" | |
// thanks to location transparency, we can select | |
// remote actors as if they where existing on local node | |
let sref = select "akka://local-system/user/hello" system | |
sref <! "Hello again" | |
// we can still create actors in local system context | |
let lref = spawn system "local" (actorOf (fun msg -> printfn "local '%s'" msg)) | |
// this message should be printed in local application console | |
lref <! "Hello locally" | |
System.Console.ReadLine() | |
0 // return an integer exit code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Akka.FSharp | |
let config = | |
Configuration.parse | |
@"akka { | |
actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" | |
remote.helios.tcp { | |
hostname = localhost | |
port = 9001 | |
} | |
}" | |
[<EntryPoint>] | |
let main args = | |
use system = System.create "remote-system" config | |
System.Console.ReadLine() | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment