Skip to content

Instantly share code, notes, and snippets.

@bobbychopra
Created October 11, 2015 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobbychopra/a81b48d6e9d384d93d63 to your computer and use it in GitHub Desktop.
Save bobbychopra/a81b48d6e9d384d93d63 to your computer and use it in GitHub Desktop.
module Program
open System
open Akka
open Akka.Actor
open Akka.FSharp
open Akka.Configuration
type Message =
| Subscribe
| Unsubscribe
| Msg of IActorRef * string
[<EntryPoint>]
let main argv =
let subscriber (mailbox:Actor<_>) msg =
let eventStream = mailbox.Context.System.EventStream
match msg with
| Msg (sender, content) -> printfn "%A says %s - %A" (sender.Path) content (mailbox.Self.Path)
| Subscribe -> subscribe typeof<Message> mailbox.Self eventStream |> ignore
| Unsubscribe -> unsubscribe typeof<Message> mailbox.Self eventStream |> ignore
let actorSystem = System.create "myActorSystem" (Configuration.load ())
let subscriber1 = spawn actorSystem "subscriber1" (actorOf2 subscriber)
let subscriber2 = spawn actorSystem "subscriber2" (actorOf2 subscriber)
let subscriber3 = spawn actorSystem "subscriber3" (actorOf2 subscriber)
let publisher = spawn actorSystem "publisher" (actorOf2
(fun mailbox msg ->
publish msg mailbox.Context.System.EventStream))
subscriber1 <! Subscribe
publisher <! Msg (publisher, "hello")
subscriber1 <! Unsubscribe
subscriber1 <! Subscribe
subscriber2 <! Subscribe
subscriber3 <! Subscribe
publisher <! Msg (publisher, "hello again")
actorSystem.AwaitTermination ()
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment